/**   
* @Title: YwShenQingZxServiceImpl.java 
* @Package com.zjdiepu.www.biz.zpp 
* 
* @author zhangpp
* @date 2017年5月26日 下午4:39:08 
* @version V1.0   
*/
package com.zjdiepu.www.biz.zpp;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.diepu.www.client.hzicbc.proxy.enums.BankCreditResultType;
import com.diepu.www.client.proxy.partner.request.own.DiepuZxCopyApplyRequest;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.enums.status.CreditQueryStatus;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.status.QueryCreditApplyStatus;
import com.zjdiepu.www.base.enums.type.AttachmentSort;
import com.zjdiepu.www.base.enums.type.CodeType;
import com.zjdiepu.www.base.enums.type.CreditPeopleType;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.ModeIDType;
import com.zjdiepu.www.base.enums.type.NewsType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.base.enums.type.TypeData;
import com.zjdiepu.www.biz.helper.ServiceHelper;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.common.util.DateUtil;
import com.zjdiepu.www.common.util.StringUtil;
import com.zjdiepu.www.common.util.ZhppDateUtil;
import com.zjdiepu.www.dao.base.SysUserMapper;
import com.zjdiepu.www.dao.icbc.YwOrdernoBankMapper;
import com.zjdiepu.www.dao.other.OtherTaskAllocationMapper;
import com.zjdiepu.www.dao.system.BaseBusiUnitMapper;
import com.zjdiepu.www.dao.system.BaseCustomerMapper;
import com.zjdiepu.www.dao.system.BaseSalersmanMapper;
import com.zjdiepu.www.dao.system.BaseSysParamsMapper;
import com.zjdiepu.www.dao.yw.YwBusinessBuyerMapper;
import com.zjdiepu.www.dao.yw.YwBusinessMapper;
import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.dao.zpp.YwShenQingZxDao;
import com.zjdiepu.www.dao.zx.ZxCreditQueryMapper;
import com.zjdiepu.www.dao.zx.ZxQueryCreditApplyMapper;
import com.zjdiepu.www.dao.zx.ZxQueryCreditApplySubMapper;
import com.zjdiepu.www.ibiz.base.IDpBaseDataDictionaryService;
import com.zjdiepu.www.ibiz.base.IOtherAttachmentsService;
import com.zjdiepu.www.ibiz.base.ISerialNumberService;
import com.zjdiepu.www.ibiz.base.ISysUserService;
import com.zjdiepu.www.ibiz.file.IQiniuFileService;
import com.zjdiepu.www.ibiz.third.IPhoneNumberAddrService;
import com.zjdiepu.www.ibiz.zpp.IcbcApiService;
import com.zjdiepu.www.ibiz.zpp.SystemService;
import com.zjdiepu.www.ibiz.zpp.YwShenQingZxService;
import com.zjdiepu.www.ibiz.zx.IZxCreditQueryService;
import com.zjdiepu.www.ibiz.zx.IZxQueryCreditApplySubService;
import com.zjdiepu.www.model.base.dto.DpBaseDataDictionary;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.base.ext.DpBaseDataDictionaryExt;
import com.zjdiepu.www.model.icbc.dto.YwOrdernoBank;
import com.zjdiepu.www.model.other.dto.OtherTaskAllocation;
import com.zjdiepu.www.model.system.dto.BaseBusiUnit;
import com.zjdiepu.www.model.system.dto.BaseCustomer;
import com.zjdiepu.www.model.system.dto.BaseSalersman;
import com.zjdiepu.www.model.system.dto.BaseSysParams;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.yw.dto.YwBusinessBuyer;
import com.zjdiepu.www.model.zpp.fksh.ext.ParamsExt;
import com.zjdiepu.www.model.zpp.fksh.vo.ParamsVo;
import com.zjdiepu.www.model.zpp.pub.ext.DiepuCreditFeedbackExt;
import com.zjdiepu.www.model.zpp.pub.ext.ZxDataResult;
import com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt;
import com.zjdiepu.www.model.zpp.ywsl.ext.QuerycredExt;
import com.zjdiepu.www.model.zpp.ywsl.ext.QuerycreditapplyExt;
import com.zjdiepu.www.model.zpp.ywsl.ext.Zx_credit_queryExt;
import com.zjdiepu.www.model.zpp.ywsl.vo.QueryFkVo;
import com.zjdiepu.www.model.zpp.ywsl.vo.Zx_credit_queryVo;
import com.zjdiepu.www.model.zx.dto.ZxCreditQuery;
import com.zjdiepu.www.model.zx.dto.ZxQueryCreditApply;
import com.zjdiepu.www.model.zx.dto.ZxQueryCreditApplySub;
import com.zjdiepu.www.model.zx.ext.ZxQueryCreditApplySubExt;
import com.zjdiepu.www.model.zx.request.DiepuCreditApplyModifyExt;
import com.zjdiepu.www.model.zx.request.ZxRestRequest;
import com.zjdiepu.www.proxy.OwnDiepuService;
import com.zjdiepu.www.response.BooleanResponse;
import com.zjdiepu.www.security.exception.BasePartnerException;
import com.zjdiepu.www.security.server.core.Partners;
import com.zjdiepu.www.util.CommonUtil;
import com.zjdiepu.www.util.ExceptionHelper;

/**      
 * 项目名称：diepu-parent-biz   
 * 类名称：YwShenQingZxServiceImpl   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月26日 下午4:39:08   
 * 修改人：zhangpp
 * 修改时间：2017年5月26日 下午4:39:08   
 * 修改备注：   
 * @version V1.0     
 */
@Service
public class YwShenQingZxServiceImpl implements YwShenQingZxService {
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private PublicDao publicDao;
	
	@Autowired
	private IZxCreditQueryService zxCreditQueryService;
	
	@Autowired
	private SystemService systemService;
	
	@Autowired
	private YwShenQingZxDao YwShenQingZxDao;
	
	@Autowired
	private ZxCreditQueryMapper zxCreditQueryMapper;
	
	@Autowired
	private ZxQueryCreditApplyMapper zxQueryCreditApplyMapper;
	
	@Autowired
	private ZxQueryCreditApplySubMapper zxQueryCreditApplySubMapper;
	
	@Autowired
	private YwBusinessMapper ywBusinessMapper;
	
	@Autowired
	private BaseCustomerMapper baseCustomerMapper;
	
	@Autowired
	private BaseSalersmanMapper baseSalersmanMapper;
	
	@Autowired
	private ISerialNumberService serialNumberService;
	
	@Autowired
	private OtherTaskAllocationMapper otherTaskAllocationMapper;
	
	@Autowired
	private IOtherAttachmentsService otherAttachmentsService;
	
	@Autowired
	private YwBusinessBuyerMapper ywBusinessBuyerMapper; 
	
	@Autowired
	private BaseSysParamsMapper baseSysParamsMapper;
	
	@Autowired
	private SysUserMapper sysUserMapper;
	
	@Autowired
	private ServiceHelper serviceHelper;
	
	@Autowired
	private ISysUserService iSysUserService;
	
	@Resource
	private IDpBaseDataDictionaryService iDpBaseDataDictionaryService;
	
	@Resource
	private IPhoneNumberAddrService phoneNubmerAddrService;
	
	@Autowired
	private OwnDiepuService ownDiepuService;
	
	@Autowired
	private IQiniuFileService iQiniuFileService;
	
	@Autowired
	private YwOrdernoBankMapper ywOrdernoBankMapper;
	
	@Autowired
	private BaseBusiUnitMapper baseBusiUnitMapper;
	
	@Autowired
	private IcbcApiService icbcApiService;
	
	@Resource
	private IZxQueryCreditApplySubService zxQueryCreditApplySubService;
	

	/* 
	* @author zhangpp
	* <p>Title: getList</p> 
	* <p>Description: </p> 
	* @param QueryFkExt
	* @param paramsExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getList(com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt, com.zjdiepu.www.model.zpp.fksh.ext.ParamsExt) 
	* @version V1.0
	*/
	@Override
	public List<QueryFkVo> getList(QueryFkExt QueryFkExt, ParamsExt paramsExt) {
		
		return YwShenQingZxDao.getList(QueryFkExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: countByExt</p> 
	* <p>Description: </p> 
	* @param QueryFkExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#countByExt(com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt) 
	* @version V1.0
	*/
	@Override
	public int countByExt(QueryFkExt QueryFkExt) {
		
		return YwShenQingZxDao.countByExt(QueryFkExt);
	}
	
	/* 
	* @author zhangpp
	* <p>Title: zxUpdateStatusTextService</p> 
	* <p>Description: </p> 
	* @param zxQueryFkExt
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#zxUpdateStatusTextService(com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void diepuZxUpdateStatusTextService(QueryFkExt zxQueryFkExt,AbstractSysUser currentUser) throws Exception {
		
 		String id = currentUser.getId();
		String name = currentUser.getName();
		
		//主表执行更新 状态值
		ZxQueryCreditApply zxQueryCreditApply = new ZxQueryCreditApply();
		zxQueryCreditApply.setQueryCreditApplyStatus(zxQueryFkExt.getQuery_credit_apply_status());
		zxQueryCreditApply.initUpdateData(id,name);
		zxQueryCreditApply.setId(zxQueryFkExt.getReplaceId());
		int updateCount = zxQueryCreditApplyMapper.updateByPrimaryKeySelective(zxQueryCreditApply);
		if(updateCount == 0) {
			ExceptionHelper.thow(String.valueOf(ResultFlagType.MISSING.getCode()), "征信申请记录丢失");
		} 
		
		//修改以及更新征信表的值
		ZxQueryCreditApplySub zxQueryCreditApplySub = new ZxQueryCreditApplySub();
		zxQueryCreditApplySub.initUpdateData(id, name);
		zxQueryCreditApplySub.setId(zxQueryFkExt.getTid());
		zxQueryCreditApplySub.setReasonBack(zxQueryFkExt.getReason_back());
		zxQueryCreditApplySub.setRemarks(zxQueryFkExt.getRemarks());
		updateCount = zxQueryCreditApplySubMapper.updateByPrimaryKeySelective(zxQueryCreditApplySub);
		if(updateCount == 0) {
			ExceptionHelper.thow(String.valueOf(ResultFlagType.MISSING.getCode()), "征信子申请记录丢失");
		}
		
		//修改以及更新征信表的值数据
		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
		zxCreditQuery.initUpdateData(id, name);
		zxCreditQuery.setId(zxQueryFkExt.getHid());
		zxCreditQuery.setStartDate(zxQueryFkExt.getStart_date());
		zxCreditQuery.setOperatorDate(zxQueryFkExt.getStart_date());
		zxCreditQuery.setEndDate(zxQueryFkExt.getEnd_date());
		zxCreditQuery.setCreditResult(zxQueryFkExt.getCredit_result());
		zxCreditQuery.setCreditResultMark(zxQueryFkExt.getCredit_result_mark());
		zxCreditQuery.setOnceCarStatus(zxQueryFkExt.getOnce_car_status());
		zxCreditQuery.setCreditQueryStatus(zxQueryFkExt.getCredit_query_status());
		zxCreditQuery.setRemarks(zxQueryFkExt.getRemarks());
		updateCount = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
		if(updateCount == 0) {
			ExceptionHelper.thow(String.valueOf(ResultFlagType.MISSING.getCode()), "征信结果记录丢失");
		} 
		
		//如果是保存状态则写业务信息表的数据
		int credit_query_status = zxCreditQuery.getCreditQueryStatus();
		int query_credit_apply_status = zxQueryCreditApply.getQueryCreditApplyStatus();
		
		//退回操作
		if(credit_query_status == 20 || query_credit_apply_status == 10) {
		    //调用发送短信推送接口
		    systemService.diepuNewsHandle(currentUser, ModeIDType.ZXCX.getCode(), NewsType.TZ01.getCode(), null, zxQueryCreditApplySub.getId());
			return;
		}
		
		//查询征信字表数据
		ZxQueryCreditApplySub sub = zxQueryCreditApplySubMapper.selectByPrimaryKey(zxQueryFkExt.getTid());
		
		//担保人 主借人  配偶的类型
		String credit_people_type = sub.getCreditPeopleType();
		
		//如果是担保人 或者配偶，@update 2018-03-02 只发送信息，不进一步操作
		if(null == credit_people_type || credit_people_type.equals("01") || credit_people_type.equals("02"))
		{
			//担保人或者配偶不做任何操作
			
			//调用发送短信推送接口
		    systemService.diepuNewsHandle(currentUser, ModeIDType.ZXCX.getCode(), NewsType.TZ03.getCode(), null, zxQueryCreditApplySub.getId());
			return;
		}
		
		//当信用状态  为：正常   或者 关注的时候
		if(zxQueryFkExt.getCredit_result().equals("01") || zxQueryFkExt.getCredit_result().equals("02"))
		{
			//查询征信 主表的数据
		    ZxQueryCreditApply zxApply =  zxQueryCreditApplyMapper.selectByPrimaryKey(zxQueryFkExt.getReplaceId());
		    
	    	   
    	    //查询业务员表数据信息
			BaseSalersman baseSalersman = baseSalersmanMapper.selectByPrimaryKey(zxApply.getSalersmanIdThen());
			
			if(null == baseSalersman) {
				ExceptionHelper.thow(String.valueOf(ResultFlagType.MISSING.getCode()), "业务员记录丢失");
			}
			
			//客户信息
			BaseCustomer baseCustomer = new BaseCustomer();
	    	baseCustomer.initInsertData(id, name);
			baseCustomer.setSalesmanId(baseSalersman.getId());
			baseCustomer.setSalesmanCode(baseSalersman.getSalersmanCode());
			baseCustomer.setSalesmanName(baseSalersman.getName());
			baseCustomer.setName(zxApply.getCustomerName());
			
			//客户编号规则：KH+8位序号
			String cus_code = "C" + DateUtil.dateTo8Str(new Date()) + new DecimalFormat("0000").format(serialNumberService.createSerialNumber(CodeType.CUSTOMER,null, false));
			//客户编号规则：KH+8位序号
			
			baseCustomer.setCusCode(cus_code);
			baseCustomer.setCusNo(zxApply.getCustomerNo());
			baseCustomer.setCusNo2(zxApply.getCustomerNo2());
			int insertCount = baseCustomerMapper.insert(baseCustomer);
			if(insertCount < 1) {
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
			} 
			
			String customerId = baseCustomer.getId();
			//客户ID
			zxApply.setCustomerId(customerId);
			
			//插入业务信息表数据
			YwBusiness ywBusiness = new YwBusiness();
			ywBusiness.initInsertData(id, name);
			
			//生成编码
			String busiCode = DateUtil.dateTo8Str(new Date()) + new DecimalFormat("00000000").format(serialNumberService.createSerialNumber(CodeType.BUSINESS,null, true));
			//生成编码
			
			ywBusiness.setBusiCode(busiCode);
			ywBusiness.setQueryCreditApplyId(zxQueryFkExt.getReplaceId());    //征信结果表的主键
			ywBusiness.setCreditQueryId(zxQueryFkExt.getHid());  //征信表主表  主键
			ywBusiness.setDealerId(zxApply.getDealerId());
			ywBusiness.setCustomerId(customerId);
			ywBusiness.setCustomerName(zxApply.getCustomerName());
			ywBusiness.setCustomerNo(zxApply.getCustomerNo());
			//料登记10
			ywBusiness.setBusiStatus(10);  
			//业务电审状态10
			ywBusiness.setPhoneStatus(10); 
			//通道状态无
			ywBusiness.setChannelStatus(10);
			//通融状态通融
			ywBusiness.setTongrongStatus(10);
			//额外状态1未定级
			ywBusiness.setAddedStatus1(10);
			//欠资料状态
			ywBusiness.setLessInformationStatus(20);  
			//归档状态为
			ywBusiness.setStatusArchive(10);
			//所处银行
			ywBusiness.setBankLoan(zxApply.getBankCode());
			//业务员id 
			ywBusiness.setSalesmanId(baseSalersman.getId());
			//业务员编码 
			ywBusiness.setSalesmanCode(baseSalersman.getSalersmanCode());
			
			//查询征信结果表数据
			ZxCreditQuery zxResult = zxCreditQueryMapper.selectByPrimaryKey(zxQueryFkExt.getHid());
			
			//征信录入时间
			ywBusiness.setOperatorDate(zxResult.getOperatorDate());
			
			//业务录入时间
			ywBusiness.setSubmitTime(new Date());
			
			//业务表执行添加
			insertCount = ywBusinessMapper.insert(ywBusiness);
			if(insertCount < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
			} 
			
			//业务编号
			zxApply.setBusiId(ywBusiness.getId());
			
			//修改征信主表
			updateCount = zxQueryCreditApplyMapper.updateByPrimaryKeySelective(zxApply);
			if(updateCount < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
			} 
			
			//业务编号
			zxResult.setBusiId(ywBusiness.getId());
			//客户编号
			zxResult.setCustomerId(customerId);
			
			//征信结果表修改
			updateCount = zxCreditQueryMapper.updateByPrimaryKeySelective(zxResult);
			if(updateCount < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
			} 
			
			//循环插入    
			String replaceId = zxQueryFkExt.getReplaceId();
			
			//循环修改征信结果表
			String sqlXmls = "select t.id from zx_credit_query t where t.query_credit_apply_id = '"+replaceId+"' and t.credit_people_type <> '03' and t.dp_status = 1";
			List<Map<String, String>> list = publicDao.queryWhereSql(sqlXmls);
			if(null != list && list.size() > 0)
			{
				for(int i=0;i<list.size();i++)
				{
					Map<String, String> maps = list.get(i);
					
					//征信结果表的主键
					ZxCreditQuery creditQuery = new ZxCreditQuery();
//					@update 2018-03-02 添加修改人和时间
					creditQuery.initUpdateData(id, name);
					creditQuery.setId(maps.get("id"));
					creditQuery.setBusiId(ywBusiness.getId());
					creditQuery.setCustomerId(customerId);
					
					//征信结果表修改
					updateCount = zxCreditQueryMapper.updateByPrimaryKeySelective(creditQuery);
					if(updateCount < 1)
					{
						throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
					} 
				}
			}
			
			//查询征信结果表
			sqlXmls = "select t.id,t.credit_people_type,t.cus_name,t.cus_no,t.tel1 from zx_query_credit_apply_sub t where t.query_credit_apply_id = '"+replaceId+"'  and t.dp_status = 1";
			list = publicDao.queryWhereSql(sqlXmls);
			if(CollectionUtils.isEmpty(list))
			{
				ExceptionHelper.thow(String.valueOf(ResultFlagType.MISSING.getCode()), "征信子申请记录丢失");
			}
			
			for(int i=0;i<list.size();i++)
			{
				Map<String, String> maps = list.get(i);
				
				String creditPeopleType = maps.get("credit_people_type");
				String cusName = maps.get("cus_name");
				String cusNo = maps.get("cus_no");
				String tel1 = maps.get("tel1");
				
				//添加yw_business_buyer表
				YwBusinessBuyer ywBusinessBuyer = new YwBusinessBuyer();
				ywBusinessBuyer.initInsertData(id, name); 
				ywBusinessBuyer.setCarManType(creditPeopleType);
				ywBusinessBuyer.setBusiId(ywBusiness.getId());
				ywBusinessBuyer.setCusId(ywBusiness.getCustomerId());
				ywBusinessBuyer.setName(cusName);
				ywBusinessBuyer.setIdno(cusNo);
				Pattern p = Pattern.compile("(\\w{3})(\\w+)(\\w{3})");  
				Matcher m = p.matcher(cusNo); 
				String idno2 = m.replaceAll("$1****$3");
				ywBusinessBuyer.setIdno2(idno2);
				ywBusinessBuyer.setTel1(tel1);
				
				//获取户籍信息
				Map<String,Object> jsonMaps = phoneNubmerAddrService.getIdCordInfo(cusNo);
				if(null != jsonMaps && !jsonMaps.isEmpty())
				{
					JSONObject json = CommonUtil.getJSONObject(jsonMaps.get("result"));	
					int isok = json.getInt("isok");
					if(isok != -1)
					{
						ywBusinessBuyer.setArea(String.valueOf(json.get("area")));
						ywBusinessBuyer.setSex("男".equals(json.getString("sex")) ? "01" : "02");
						ywBusinessBuyer.setFamilyRegister(String.valueOf(json.get("province")));
					}
				}
				
				insertCount = ywBusinessBuyerMapper.insert(ywBusinessBuyer);
				if(insertCount < 1)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
				} 
			}
			
			//额外事件调用
			systemService.diepuNewsHandleExtra(currentUser, ywBusiness.getId());
			
			//调用发送短信推送接口
		    systemService.diepuNewsHandle(currentUser, ModeIDType.ZXCX.getCode(), NewsType.TZ03.getCode(), ywBusiness.getId(), zxQueryCreditApplySub.getId());
			return;
		}
		
		//调用发送短信推送接口
	    systemService.diepuNewsHandle(currentUser, ModeIDType.ZXCX.getCode(), NewsType.TZ03.getCode(), null, zxQueryCreditApplySub.getId());
	}
	
	/* 
	* @author zhangpp
	* <p>Title: getSQServiceById</p> 
	* <p>Description: </p> 
	* @param zxQueryFkExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getSQServiceById(com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt) 
	* @version V1.0
	*/
	@Override
	public List<QueryFkVo> getSQServiceById(QueryFkExt zxQueryFkExt) {
		
		return YwShenQingZxDao.getSQById(zxQueryFkExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: zxUpdate</p> 
	* <p>Description: </p> 
	* @param zxQuerycredExt
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#zxUpdate(com.zjdiepu.www.model.examine.ext.QuerycredExt, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void diepuZxUpdate(QuerycredExt zxQuerycredExt,AbstractSysUser currentUser, boolean isApply)throws Exception
	{
		
		String id = currentUser.getId();
		String name = currentUser.getName();
		
		String queryCreditApplyId = zxQuerycredExt.getZx_query_credit_apply_id();
		
		//配偶01   担保人02 主借人	03
		String creditPeopleType = zxQuerycredExt.getCredit_people_type();
		
		//征信查询结果表  更新
		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
		zxCreditQuery.setId(zxQuerycredExt.getZx_credit_query_id());
		zxCreditQuery.setBankCode(zxQuerycredExt.getBank_code());
		zxCreditQuery.setSalersmanIdThen(zxQuerycredExt.getSalersman_id_then());
		zxCreditQuery.setCreditQueryStatus(10);
		int count = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxCreditQueryMapper updateByPrimaryKeySelective error");
		} 
		
		if(CreditPeopleType.ZHU_JIE_REN.getCode().equals(creditPeopleType)) {
			//征信查询申请
			ZxQueryCreditApply zxQueryCreditApply = new ZxQueryCreditApply();
			zxQueryCreditApply.setId(zxQuerycredExt.getZx_query_credit_apply_id());
			zxQueryCreditApply.initUpdateData(id, name);
			zxQueryCreditApply.setSalersmanIdThen(zxQuerycredExt.getSalersman_id_then());
			zxQueryCreditApply.setBankCode(zxQuerycredExt.getBank_code());
			zxQueryCreditApply.setCustomerName(zxQuerycredExt.getCustomer_name());
			zxQueryCreditApply.setCustomerNo(zxQuerycredExt.getCustomer_no());
			zxQueryCreditApply.setBankCode(zxQuerycredExt.getBank_code());
			zxQueryCreditApply.setQueryCreditApplyStatus(Integer.valueOf(zxQuerycredExt.getQuery_credit_apply_status()));
			count = zxQueryCreditApplyMapper.updateByPrimaryKeySelective(zxQueryCreditApply);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplyMapper updateByPrimaryKeySelective error");
			} 
		}
		
		//征信查询申请子表
		ZxQueryCreditApplySub zxQueryCreditApplySub = new ZxQueryCreditApplySub();
		zxQueryCreditApplySub.setId(zxQuerycredExt.getZx_query_credit_apply_sub_id());
		zxQueryCreditApplySub.initUpdateData(id, name);
		zxQueryCreditApplySub.setBankCode(zxCreditQuery.getBankCode());
		zxQueryCreditApplySub.setCusName(zxQuerycredExt.getCustomer_name());
		zxQueryCreditApplySub.setCusNo(zxQuerycredExt.getCustomer_no());
		zxQueryCreditApplySub.setTel1(zxQuerycredExt.getTel1());
		count = zxQueryCreditApplySubMapper.updateByPrimaryKeySelective(zxQueryCreditApplySub);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplySubMapper updateByPrimaryKeySelective error");
		} 
		
		
		//不修改主借人的
		if(!creditPeopleType.equals("03"))
		{
			YwBusiness ywBusiness = new YwBusiness();
			ywBusiness.setQueryCreditApplyId(queryCreditApplyId);
			ywBusiness.setDpStatus(1);
			ywBusiness = ywBusinessMapper.selectRefined(ywBusiness);
			if(null != ywBusiness)
			{
				YwBusinessBuyer ywBusinessBuyer = new YwBusinessBuyer();
				ywBusinessBuyer.setBusiId(ywBusiness.getId());
				// 确认唯一购车人  @update 2018-03-09
				ywBusinessBuyer.setIdno(zxQuerycredExt.getCustomer_no());
				ywBusinessBuyer.setCarManType(creditPeopleType);
				ywBusinessBuyer.setDpStatus(1);
				ywBusinessBuyer = ywBusinessBuyerMapper.selectRefined(ywBusinessBuyer);
				if(null != ywBusinessBuyer)
				{
					ywBusinessBuyer.setName(zxQueryCreditApplySub.getCusName());
					ywBusinessBuyer.setIdno(zxQueryCreditApplySub.getCusNo());
					ywBusinessBuyer.setIdno2(zxQueryCreditApplySub.getCusNo2());
					ywBusinessBuyer.setTel1(zxQueryCreditApplySub.getTel1());
					
					//获取户籍信息
					Map<String,Object> jsonMaps = phoneNubmerAddrService.getIdCordInfo(zxQueryCreditApplySub.getCusNo());
					if(null != jsonMaps && !jsonMaps.isEmpty())
					{
						JSONObject json = CommonUtil.getJSONObject(jsonMaps.get("result"));	
						int isok = json.getInt("isok");
						if(isok != -1)
						{
							ywBusinessBuyer.setArea(String.valueOf(json.get("area")));
							ywBusinessBuyer.setSex("男".equals(json.getString("sex")) ? "01" : "02");
							ywBusinessBuyer.setFamilyRegister(String.valueOf(json.get("province")));
						}
					}
					count = ywBusinessBuyerMapper.updateByPrimaryKeySelective(ywBusinessBuyer);
					if(count < 1)
					{
						throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessBuyerMapper error");
					}
				}
			}
		}
		
		serviceHelper.checkIdNoDuplicate(queryCreditApplyId);
	}

	/* 
	* @author zhangpp
	* <p>Title: saveZx</p> 
	* <p>Description: </p> 
	* @param zxQuerycredExt
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#saveZx(com.zjdiepu.www.model.examine.ext.QuerycredExt, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void diepuZxApply(QuerycredExt zxQuerycredExt, AbstractSysUser currentUser, boolean isApply) throws Exception {
		//检查是有有用户正在申请征信
		checkApplyingZx(zxQuerycredExt, false);
		//获取征信客户的信息数据
		QuerycreditapplyExt zxQuerycreditapplyExt = zxQuerycredExt.getKehuExt();
		List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = new ArrayList<ZxQueryCreditApplySub>();
		String zxQueryCreditApplySubId = null;
		String bankCode = "";
		
		//必须有条数据信息
		if(null != zxQuerycreditapplyExt && StringUtils.isNotBlank(zxQuerycreditapplyExt.getCustomer_name())) {
			//添加主借人
			ZxQueryCreditApplySub zxQueryCreditApplySub = saveZhuJieRen(zxQuerycreditapplyExt, currentUser);
			zxQueryCreditApplySubId = "主借人";
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
			bankCode = zxQuerycreditapplyExt.getBank_code();
		}
		
		//配偶执行添加
		QuerycreditapplyExt po = zxQuerycredExt.getPoExt();
		if(null != po && StringUtils.isNotBlank(po.getCustomer_name()))
		{
			//添加配偶信息
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(po,zxQueryCreditApplySubId,currentUser);
			//检查配偶
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
			bankCode = po.getBank_code();
		}
		
		//担保人1执行添加
		QuerycreditapplyExt db1 = zxQuerycredExt.getDb1Ext();
		if(null != db1 && StringUtils.isNotBlank(db1.getCustomer_name()))
		{
			//添加担保人
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(db1,zxQueryCreditApplySubId,currentUser);
			//检查担保人
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
			bankCode = db1.getBank_code();
		}
		
		//担保人2执行添加
		QuerycreditapplyExt db2 = zxQuerycredExt.getDb2Ext();
		if(null != db2 && StringUtils.isNotBlank(db2.getCustomer_name()))
		{
			//添加担保人
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(db2,zxQueryCreditApplySubId,currentUser);
			//检查担保人
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
			bankCode = db2.getBank_code();
		}
		
		//担保人3执行添加
		QuerycreditapplyExt db3 = zxQuerycredExt.getDb3Ext();
		if(null != db3 && StringUtils.isNotBlank(db3.getCustomer_name()))
		{
			//添加担保人
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(db3,zxQueryCreditApplySubId,currentUser);
			//检查担保人
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
			bankCode = db3.getBank_code();
		}
		
		//担保人4执行添加
		QuerycreditapplyExt db4 = zxQuerycredExt.getDb4Ext();
		if(null != db4 && StringUtils.isNotBlank(db4.getCustomer_name()))
		{
			//添加担保人
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(db4,zxQueryCreditApplySubId,currentUser);
			//检查担保人
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
			bankCode = db4.getBank_code();
		}
		
		//筛选
		diepuApplyQuery(currentUser,zxQueryCreditApplySubs,bankCode);
		
		//下载征信文档
//		@update 2018-02-06 征信文档生成另开事务
//		diepuDownloadWord(queryCreditApplyId,currentUser);
	}
	
	@Override
	public void saveApply(ZxRestRequest zxRestRequest, SysUser currentUser, boolean isApply) {
		//检查是否正在查询征信
		checkApplyingZx(zxRestRequest, false);
		ZxQueryCreditApply zxQueryCreditApply = zxRestRequest.getZxQueryCreditApply();
		String applyId = zxQueryCreditApply.getId();
		zxQueryCreditApply.initInsertData(currentUser.getId(), currentUser.getName());
		zxQueryCreditApply.setId(applyId);
		DecimalFormat decimalFormat = new DecimalFormat("00000000");
		Integer queryCreditApplySerialNumber = serialNumberService.createSerialNumber(CodeType.CREDIT_APPLY, null, true);
		Date now = new Date();
		String formatNow = DateUtil.dateToFormat(now, "yyyyMMdd");
		
		String queryCreditApplyCode = "ZXCXSQ" + formatNow + decimalFormat.format(queryCreditApplySerialNumber);
		zxQueryCreditApply.setQueryCreditApplyCode(queryCreditApplyCode);
		zxQueryCreditApply.setQueryCreditApplyStatus(20);//提交
		zxQueryCreditApply.setCustomerNo2(StringUtil.subWithNHeadMTail(zxQueryCreditApply.getCustomerNo(), 5, 4, "*"));
		List<ZxCreditQuery> zxCreditQuerys = CollectionInitUtil.emptyList();
    	List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = zxRestRequest.getZxQueryCreditApplySubs();
    	for(ZxQueryCreditApplySub zxQueryCreditApplySub : zxQueryCreditApplySubs) {
    		String applySubId = zxQueryCreditApplySub.getId();
    		zxQueryCreditApplySub.initInsertData(currentUser.getId(), currentUser.getName());
    		zxQueryCreditApplySub.setId(applySubId);
    		zxQueryCreditApplySub.setQueryCreditApplyId(applyId);
    		zxQueryCreditApplySub.setQueryStatus(10);//待查询
    		
    		//征信查询表添加
    		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
    		Integer creditQuerySerialNumber = serialNumberService.createSerialNumber(CodeType.CREDIT_QUERY, null, true);
    		String zxCreditQueryCode = "ZXCX" + formatNow + decimalFormat.format(creditQuerySerialNumber);
    		zxCreditQuery.initInsertData(currentUser.getId(), currentUser.getName());
    		zxCreditQuery.setCreditQueryStatus(10);//待查询
    		zxCreditQuery.setCreditQueryCode(zxCreditQueryCode);
    		zxCreditQuery.setQueryCreditApplyId(applyId);
    		zxCreditQuery.setQueryCreditApplySubId(applySubId);
    		zxCreditQuery.setCreditQueryCode(String.valueOf(queryCreditApplyCode));
    		zxCreditQuery.setCreditPeopleType(zxQueryCreditApplySub.getCreditPeopleType());
    		zxCreditQuery.setCustomerId(zxQueryCreditApply.getCustomerId());
    		zxCreditQuery.setBankCode(zxQueryCreditApply.getBankCode());
    		zxCreditQuery.setSalersmanIdThen(zxQueryCreditApply.getSalersmanIdThen());
    		zxCreditQuerys.add(zxCreditQuery);
    	}
    	zxQueryCreditApplyMapper.insert(zxQueryCreditApply);
    	zxQueryCreditApplySubMapper.insertBatch(zxQueryCreditApplySubs);
    	zxCreditQueryMapper.insertBatch(zxCreditQuerys);
	}
	
	
	//主借人添加信息
	private ZxQueryCreditApplySub saveZhuJieRen(QuerycreditapplyExt zxQuerycreditapplyExt,AbstractSysUser currentUser)
	{
		//当前登录信息
		String id = currentUser.getId();
		String name = currentUser.getName();
		
		//生成的编号体系
		String queryCreditApplyCode = "ZXCXSQ" + DateUtil.dateTo8Str(new Date()) + new DecimalFormat("0000000").format(serialNumberService.createSerialNumber(CodeType.CREDIT_APPLY,null, false));
		
		//生成征信主表信息
		ZxQueryCreditApply zxQueryCreditApply = new ZxQueryCreditApply();
		zxQueryCreditApply.initInsertData(id, name);
		zxQueryCreditApply.setQueryCreditApplyCode(String.valueOf(queryCreditApplyCode));
		zxQueryCreditApply.setId(zxQuerycreditapplyExt.getId());
		zxQueryCreditApply.setDealerId(zxQuerycreditapplyExt.getDealer_id());
		zxQueryCreditApply.setSalersmanIdThen(zxQuerycreditapplyExt.getSalersman_id_then());
		zxQueryCreditApply.setBankCode(zxQuerycreditapplyExt.getBank_code());
		zxQueryCreditApply.setCustomerId(zxQuerycreditapplyExt.getCustomer_id());
		zxQueryCreditApply.setCustomerName(zxQuerycreditapplyExt.getCustomer_name());
		zxQueryCreditApply.setCustomerNo(zxQuerycreditapplyExt.getCustomer_no());
		
		//身份证加密
		//String customer_no2 = Base64With.encode(zxQuerycreditapplyExt.getCustomer_no());
		//身份证加密
		
		//zxQuerycreditapplyExt.setCustomer_no2(customer_no2);
		zxQueryCreditApply.setCustomerNo2(zxQuerycreditapplyExt.getCustomer_no2());
		zxQueryCreditApply.setQueryCreditApplyStatus(Integer.valueOf(zxQuerycreditapplyExt.getQuery_credit_apply_status()));
		zxQueryCreditApply.setClientType(zxQuerycreditapplyExt.getClient_type());
		zxQueryCreditApply.setTypeData(zxQuerycreditapplyExt.getTypeData());
		int count = zxQueryCreditApplyMapper.insert(zxQueryCreditApply);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplyMapper insert error");
		}
		
		//征信主表信息	
		ZxQueryCreditApplySub zxQueryCreditApplySub = new ZxQueryCreditApplySub();
		zxQueryCreditApplySub.initInsertData(currentUser.getId(), currentUser.getName());
//		@update 2018-02-05 
		zxQueryCreditApplySub.setId(zxQuerycreditapplyExt.getSubId());
		zxQueryCreditApplySub.setQueryCreditApplyId(zxQuerycreditapplyExt.getId());
		zxQueryCreditApplySub.setBankCode(zxQuerycreditapplyExt.getBank_code());
		zxQueryCreditApplySub.setCreditPeopleType(zxQuerycreditapplyExt.getCredit_people_type());
		zxQueryCreditApplySub.setCusName(zxQuerycreditapplyExt.getCustomer_name());
		zxQueryCreditApplySub.setCusNo(zxQuerycreditapplyExt.getCustomer_no());
		zxQueryCreditApplySub.setCusNo2(zxQuerycreditapplyExt.getCustomer_no2());
		zxQueryCreditApplySub.setTel1(zxQuerycreditapplyExt.getTel1());
		
		//暂时空着
		zxQueryCreditApplySub.setWordUrl("");
		//暂时空着
		
		//暂时空着
		zxQueryCreditApplySub.setWordOssKey("");
		//暂时空着
		
		zxQueryCreditApplySub.setQueryStatus(0);
		zxQueryCreditApplySub.setStatusAttachments("");
		zxQueryCreditApplySub.setTypeData(zxQuerycreditapplyExt.getTypeData());
		count = zxQueryCreditApplySubMapper.insert(zxQueryCreditApplySub);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplySubMapper insert error");
		}
		
		//征信查询表添加
		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
		zxCreditQuery.initInsertData(id, name);
		zxCreditQuery.setCreditQueryStatus(Integer.valueOf(zxQuerycreditapplyExt.getCredit_query_status()));
		zxCreditQuery.setQueryCreditApplyId(zxQuerycreditapplyExt.getId());
		zxCreditQuery.setQueryCreditApplySubId(zxQueryCreditApplySub.getId());
		zxCreditQuery.setCreditQueryCode(String.valueOf(queryCreditApplyCode));
		zxCreditQuery.setCreditPeopleType(zxQuerycreditapplyExt.getCredit_people_type());
		zxCreditQuery.setCustomerId(zxQuerycreditapplyExt.getCustomer_id());
		zxCreditQuery.setBankCode(zxQuerycreditapplyExt.getBank_code());
		zxCreditQuery.setSalersmanIdThen(zxQuerycreditapplyExt.getSalersman_id_then());
		//zxCreditQuery.setOperatorId(currentUser.getId());
		//zxCreditQuery.setOperatorName(currentUser.getName());
		zxCreditQuery.setOperatorDate(ZhppDateUtil.strToTimestamp(DateUtil.dateToFormat(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss"));
		zxCreditQuery.setTypeData(zxQuerycreditapplyExt.getTypeData());
		count = zxCreditQueryMapper.insert(zxCreditQuery);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxCreditQueryMapper insert error");
		}
		return zxQueryCreditApplySub;
	}
	
	//配偶添加  担保人添加
	private ZxQueryCreditApplySub diepuPeiDanBaoRen(QuerycreditapplyExt zxQuerycreditapplyExt,String zxQueryCreditApplySubId,AbstractSysUser currentUser) throws Exception
	{
		String id = currentUser.getId();
		String name = currentUser.getName();
		
		//生成的编号体系
		String queryCreditApplyCode = "ZXCXSQ" + DateUtil.dateTo8Str(new Date()) + new DecimalFormat("0000000").format(serialNumberService.createSerialNumber(CodeType.CREDIT_APPLY,null, false));
		
		//身份证需要加密
		//String customer_no2 = Base64With.encode(zxQuerycreditapplyExt.getCustomer_no());
		//zxQuerycreditapplyExt.setCustomer_no2(customer_no2);
		//身份证需要加密
		
		//征信查询表
		ZxQueryCreditApplySub zxQueryCreditApplySub = new ZxQueryCreditApplySub();
		zxQueryCreditApplySub.initInsertData(id, name);
		zxQueryCreditApplySub.setQueryCreditApplyId(zxQuerycreditapplyExt.getId());
		zxQueryCreditApplySub.setBankCode(zxQuerycreditapplyExt.getBank_code());
		zxQueryCreditApplySub.setCreditPeopleType(zxQuerycreditapplyExt.getCredit_people_type());
		zxQueryCreditApplySub.setCusName(zxQuerycreditapplyExt.getCustomer_name());
		zxQueryCreditApplySub.setCusNo(zxQuerycreditapplyExt.getCustomer_no());
		zxQueryCreditApplySub.setCusNo2(zxQuerycreditapplyExt.getCustomer_no2());
		zxQueryCreditApplySub.setTel1(zxQuerycreditapplyExt.getTel1());
		
		//暂时空着
		zxQueryCreditApplySub.setWordUrl("");
		//暂时空着
		
		//暂时空着
		zxQueryCreditApplySub.setWordOssKey("");
		//暂时空着
		
		zxQueryCreditApplySub.setQueryStatus(0);
		
		//暂时空着
		zxQueryCreditApplySub.setStatusAttachments("");
		//暂时空着
		
		zxQueryCreditApplySub.setId(zxQuerycreditapplyExt.getPoDbId());
		zxQueryCreditApplySub.setTypeData(zxQuerycreditapplyExt.getTypeData());
		int count = zxQueryCreditApplySubMapper.insert(zxQueryCreditApplySub);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplySubMapper insert error");
		}
		
		//征信子表查询
		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
		zxCreditQuery.initInsertData(id, name);
		zxCreditQuery.setQueryCreditApplyId(zxQuerycreditapplyExt.getId());
		zxCreditQuery.setQueryCreditApplySubId(zxQueryCreditApplySub.getId());
		zxCreditQuery.setCreditQueryCode(String.valueOf(queryCreditApplyCode));
		zxCreditQuery.setCreditPeopleType(zxQuerycreditapplyExt.getCredit_people_type());
		zxCreditQuery.setCustomerId(zxQuerycreditapplyExt.getCustomer_id());
		zxCreditQuery.setBankCode(zxQuerycreditapplyExt.getBank_code());
		zxCreditQuery.setSalersmanIdThen(zxQuerycreditapplyExt.getSalersman_id_then());
		//zxCreditQuery.setOperatorId(id);
		//zxCreditQuery.setOperatorName(name);
		zxCreditQuery.setOperatorDate(ZhppDateUtil.strToTimestamp(DateUtil.dateToFormat(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss"));
		zxCreditQuery.setCreditQueryStatus(Integer.valueOf(zxQuerycreditapplyExt.getCredit_query_status()));
		zxCreditQuery.setTypeData(zxQuerycreditapplyExt.getTypeData());
		count = zxCreditQueryMapper.insert(zxCreditQuery);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxCreditQueryMapper insert error");
		}
		
		//添加担保人执行
		if(StringUtils.isBlank(zxQueryCreditApplySubId))
		{
			//添加购车人信息
			saveBusinessBuyer(zxQueryCreditApplySub.getId(),currentUser);
		}
		return zxQueryCreditApplySub;
	}
	
	
	//添加购车人信息
	private void saveBusinessBuyer(String id,AbstractSysUser currentUser) throws Exception
	{
		String userId = currentUser.getId();
		String loginName = currentUser.getName();
		
		//征信子表
		ZxQueryCreditApplySub zxQueryCreditApplySub = zxQueryCreditApplySubMapper.selectByPrimaryKey(id);
		if(null != zxQueryCreditApplySub)
		{
			//查询业务表
			YwBusiness business = new YwBusiness();
			business.setQueryCreditApplyId(zxQueryCreditApplySub.getQueryCreditApplyId());
			business.setDpStatus(1);
			business = ywBusinessMapper.selectRefined(business);
			if(null != business)
			{
				YwBusinessBuyer ywBusinessBuyer = new YwBusinessBuyer();
				ywBusinessBuyer.initInsertData(userId, loginName);
				ywBusinessBuyer.setCarManType(zxQueryCreditApplySub.getCreditPeopleType());
				ywBusinessBuyer.setBusiId(business.getId());
				ywBusinessBuyer.setCusId(business.getCustomerId());
				ywBusinessBuyer.setIdno(zxQueryCreditApplySub.getCusNo());
				ywBusinessBuyer.setName(zxQueryCreditApplySub.getCusName());
				ywBusinessBuyer.setIdno2(zxQueryCreditApplySub.getCusNo2());
				ywBusinessBuyer.setTel1(zxQueryCreditApplySub.getTel1());
				
				//获取户籍信息
				Map<String,Object> jsonMaps = phoneNubmerAddrService.getIdCordInfo(zxQueryCreditApplySub.getCusNo());
				if(null != jsonMaps && !jsonMaps.isEmpty())
				{
					JSONObject json = CommonUtil.getJSONObject(jsonMaps.get("result"));	
					int isok = json.getInt("isok");
					if(isok != -1)
					{
						ywBusinessBuyer.setArea(String.valueOf(json.get("area")));
						ywBusinessBuyer.setSex("男".equals(json.getString("sex")) ? "01" : "02");
						ywBusinessBuyer.setFamilyRegister(String.valueOf(json.get("province")));
					}
				}
				
				int count = ywBusinessBuyerMapper.insert(ywBusinessBuyer);
				if(count < 1)
				{
					throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"insert ywBusinessBuyerMapper fail");
				} 
			}
		}
	}

	/* 
	* @author zhangpp
	* <p>Title: getOpList</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getOpList(com.zjdiepu.www.model.zpp.fksh.ext.ParamsExt) 
	* @version V1.0
	*/
	@Override
	public List<com.zjdiepu.www.model.zpp.fksh.vo.ParamsVo> getOpList(
			ParamsExt paramsExt) {
		
		return YwShenQingZxDao.getOpList(paramsExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: getCreditQueryList</p> 
	* <p>Description: </p> 
	* @param zx_credit_queryExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getCreditQueryList(com.zjdiepu.www.model.zpp.ywsl.ext.Zx_credit_queryExt) 
	* @version V1.0
	*/
	@Override
	public List<com.zjdiepu.www.model.zpp.ywsl.vo.Zx_credit_queryVo> getCreditQueryList(
			com.zjdiepu.www.model.zpp.ywsl.ext.Zx_credit_queryExt zx_credit_queryExt) {
		
		return YwShenQingZxDao.getCreditQueryList(zx_credit_queryExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: getCreditQueryCount</p> 
	* <p>Description: </p> 
	* @param zx_credit_queryExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getCreditQueryCount(com.zjdiepu.www.model.zpp.ywsl.ext.Zx_credit_queryExt) 
	* @version V1.0
	*/
	@Override
	public int getCreditQueryCount(
			com.zjdiepu.www.model.zpp.ywsl.ext.Zx_credit_queryExt zx_credit_queryExt) {
		
		return YwShenQingZxDao.getCreditQueryCount(zx_credit_queryExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: saveZhengXinData</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#saveZhengXinData(com.zjdiepu.www.model.zpp.fksh.ext.ParamsExt, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void saveZhengXinData(ParamsExt paramsExt,AbstractSysUser currentUser) 
	{
		
		String id = currentUser.getId();
		String name = currentUser.getName();
		
		//强制指定配单数据
		if(paramsExt.getZxFenPeiCode().equals("1"))
		{
			if(null != paramsExt && null != paramsExt.getReplaceId() && !("").equals(paramsExt.getReplaceId()))
			{
				String[] temp = paramsExt.getReplaceId().split(",");
				
				String uid = paramsExt.getUid();
				String uname = paramsExt.getUname();
				
				for(int i=0;i<temp.length;i++)
				{
					OtherTaskAllocation otherTaskAllocation = new OtherTaskAllocation();
					otherTaskAllocation.initInsertData(id, name);
					otherTaskAllocation.setModeId("ZXCXSQ");
					otherTaskAllocation.setDataid(temp[i]);
					otherTaskAllocation.setAlloterId(id);
					otherTaskAllocation.setAlloterName(name);
					otherTaskAllocation.setReceiverId(uid);
					otherTaskAllocation.setReceiverName(uname);
					int insertCount = otherTaskAllocationMapper.insert(otherTaskAllocation);
					if(insertCount == 0)
					{
						throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
					} 
					else if(insertCount > 1)
					{
						throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
					}
					
					//修改征信结果表的数据
					
					//当前的时间
					Date time = ZhppDateUtil.strToTimestamp(ZhppDateUtil.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss");
					//当前的时间
					
					ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
					zxCreditQuery.initUpdateData(id, name);
					zxCreditQuery.setId(temp[i]);
					zxCreditQuery.setOperatorId(uid);
					zxCreditQuery.setOperatorName(uname);
					zxCreditQuery.setAcceptDate(time);
					int updateCount = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
					if(updateCount == 0)
					{
						throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
					} 
					else if(updateCount > 1)
					{
						throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
					}
				}
			}
			return;
		}
		
		//查询出那些数据是需要分配的   征信结果数据
		Zx_credit_queryExt zx_credit_queryExt = new Zx_credit_queryExt();
		String whereSql = " and h.operator_id is null ";
		zx_credit_queryExt.setWhereSql(whereSql);
		zx_credit_queryExt.withOutPage();
		List<Zx_credit_queryVo> dhywDyVos = YwShenQingZxDao.getCreditQueryList(zx_credit_queryExt);
		
		//查询那些操作员是要分配的
		//随机派单不包含自己
		whereSql = "and v.id <> '"+id+"'";
		paramsExt.setWhereSql(whereSql);
		List<ParamsVo> paramsVo = YwShenQingZxDao.getOpList(paramsExt);
		
		int j = 0;
		
		//我分配的单数一定 大于等于 我待分单的单数
		if(dhywDyVos.size() >= paramsExt.getAllocationNum())
		{
			//开始分单操作
			for(int i=0;i<paramsExt.getAllocationNum();i++)
			{
				OtherTaskAllocation otherTaskAllocation = new OtherTaskAllocation();
				otherTaskAllocation.initInsertData(id, name);
				otherTaskAllocation.setModeId("ZXCXSQ");
				otherTaskAllocation.setDataid(dhywDyVos.get(i).getReplaceId());
				otherTaskAllocation.setAlloterId(id);
				otherTaskAllocation.setAlloterName(name);
				
				if(j >= paramsVo.size())
				{
					j = 0;
				}
				
				//分配人的信息
				String uid = paramsVo.get(j).getReplaceId();
				String uname = paramsVo.get(j).getUname();
				
				otherTaskAllocation.setReceiverId(uid);
				otherTaskAllocation.setReceiverName(uname);
				int insertCount = otherTaskAllocationMapper.insert(otherTaskAllocation);
				if(insertCount == 0)
				{
					throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
				} 
				else if(insertCount > 1)
				{
					throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
				}
				
				//修改征信结果表的数据
				
				//当前的时间
				Date time = ZhppDateUtil.strToTimestamp(ZhppDateUtil.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss");
				//当前的时间
				
				ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
				zxCreditQuery.initUpdateData(id, name);
				zxCreditQuery.setId(dhywDyVos.get(i).getReplaceId());
				zxCreditQuery.setOperatorId(uid);
				zxCreditQuery.setOperatorName(uname);
				zxCreditQuery.setAcceptDate(time);
				int updateCount = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
				if(updateCount == 0)
				{
					throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
				} 
				else if(updateCount > 1)
				{
					throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
				}
				
				j ++;
			}
		}
	}

	/* 
	* @author zhangpp
	* <p>Title: getEntity</p> 
	* <p>Description: </p> 
	* @param QueryFkExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getEntity(com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt) 
	* @version V1.0
	*/
	@Override
	public QueryFkVo getEntity(QueryFkExt QueryFkExt) {
		
		return YwShenQingZxDao.getEntity(QueryFkExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: deleteAttachments</p> 
	* <p>Description: </p> 
	* @param dataId
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#deleteAttachments(java.lang.String) 
	* @version V1.0
	*/
	@Override
	public int deleteAttachments(String dataId) {
		
		return YwShenQingZxDao.deleteAttachments(dataId);
	}

	/* 
	* @author zhangpp
	* <p>Title: extZhengxin</p> 
	* <p>Description: </p> 
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#extZhengxin(com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void diepuExtZhengxin(int pass,AbstractSysUser currentUser) {
		
		
		String userId = currentUser.getId();
		String logName = currentUser.getName();
		
		//查询征信未派单的
		String sqlXmls = " select t.id from zx_credit_query t where t.operator_id is null and t.dp_status = 1 ";
		
		SysUser sysUser = new SysUser();
		sysUser.setId(currentUser.getId());
		sysUser.setDpStatus(1);
		sysUser = sysUserMapper.selectRefined(sysUser);
		
		
		String lBank = sysUser.getLoanBank();
		DpBaseDataDictionaryExt  dpBaseDataDictionaryExt = new DpBaseDataDictionaryExt();
		dpBaseDataDictionaryExt.setBaseWhere();
		dpBaseDataDictionaryExt.withOutPage();
		dpBaseDataDictionaryExt.setParentValue(DataDicType.LOAN_BANK.getCode());
		List<DpBaseDataDictionary> list = iDpBaseDataDictionaryService.selectByExt(dpBaseDataDictionaryExt);
		if(null != list && list.size() > 0)
		{
			List<String> tmpe = iSysUserService.listBankCodes(lBank);
			sqlXmls += " and t.bank_code in ( '@@@',";
			for(int i=0;i<list.size();i++)
			{
				DpBaseDataDictionary dp =  list.get(i);
				
				if(tmpe.contains(dp.getValue()))
				{
					sqlXmls += "'"+list.get(i).getValue()+"',";
				}
			}
			sqlXmls = sqlXmls.substring(0,sqlXmls.length()-1);
			sqlXmls += " ) ";
		}
		
		
		List<Map<String, String>> creditMaps = publicDao.queryWhereSql(sqlXmls);
		
		if(null == creditMaps || ("").equals(creditMaps) || 0 == creditMaps.size())
		{
			throw new BaseException("100900","目前没有可申请的单数！");
		}
		
		//查询数据字典
		BaseSysParams baseSysParams = new BaseSysParams();
		baseSysParams.setCodeParam("TaskAssignNum_Credit");
		baseSysParams.setDpStatus(1);
		baseSysParams = baseSysParamsMapper.selectRefined(baseSysParams);
		
		if(null == baseSysParams || ("").equals(baseSysParams))
		{
			return;
		}
		
		String whereSql = "and v.id = '"+userId+"' ";
		ParamsExt paramsExt = new ParamsExt();
		paramsExt.setWhereSql(whereSql);
		List<ParamsVo> paramsVo = YwShenQingZxDao.getOpList(paramsExt);
		
		if(null == paramsVo || 0 == paramsVo.size())
		{
			return;
		}
		
		//分派的单数
		int value_param = Integer.valueOf(baseSysParams.getValueParam());
		
		if(value_param < 1)
		{
			throw new BaseException("100900","请联系部门主管指定分配的单数！");
		}
		
	    if(pass <= value_param)
	    {
	    	value_param = pass;
	    }
	    
	    if(pass > value_param)
	    {
	    	throw new BaseException("100900","申请分配的数量不能超过系统设置的数量。系统数量为："+value_param+"个！");
	    }
		
	    if(creditMaps.size() <= value_param)
	    {
	    	for(int i=0;i<creditMaps.size();i++)
	    	{
	    		Map<String, String> maps = creditMaps.get(i);
	    		
	    		String dataId = maps.get("id");
	    		
	    		String receiverId = paramsVo.get(0).getReplaceId();
	    		String receiverName = paramsVo.get(0).getUname();
	    		
	    		OtherTaskAllocation otherTaskAllocation = new OtherTaskAllocation();
				otherTaskAllocation.initInsertData(userId, logName);
				otherTaskAllocation.setModeId("ZXCXSQ");
				otherTaskAllocation.setDataid(dataId);
				otherTaskAllocation.setAlloterId("");
				otherTaskAllocation.setAlloterName("");
				otherTaskAllocation.setReceiverId(receiverId);
				otherTaskAllocation.setReceiverName(receiverName);
				int insertCount = otherTaskAllocationMapper.insert(otherTaskAllocation);
				if(insertCount == 0)
				{
					throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
				} 
				
				//当前的时间
				Date time = ZhppDateUtil.strToTimestamp(ZhppDateUtil.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss");
				//当前的时间
				
				ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
				zxCreditQuery.initUpdateData(userId, logName);
				zxCreditQuery.setId(dataId);
				zxCreditQuery.setOperatorId(receiverId);
				zxCreditQuery.setOperatorName(receiverName);
				zxCreditQuery.setAcceptDate(time);
				int updateCount = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
				if(updateCount == 0)
				{
					throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
				} 
				else if(updateCount > 1)
				{
					throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
				}
	    	}
	    	return;
	    }
	    
	    for(int i=1;i<=value_param;i++)
	    {
	    	Map<String, String> maps = creditMaps.get(i);
    		
    		String dataId = maps.get("id");
    		
    		String receiverId = paramsVo.get(0).getReplaceId();
    		String receiverName = paramsVo.get(0).getUname();
    		
    		OtherTaskAllocation otherTaskAllocation = new OtherTaskAllocation();
			otherTaskAllocation.initInsertData(userId, logName);
			otherTaskAllocation.setModeId("ZXCXSQ");
			otherTaskAllocation.setDataid(dataId);
			otherTaskAllocation.setAlloterId("");
			otherTaskAllocation.setAlloterName("");
			otherTaskAllocation.setReceiverId(receiverId);
			otherTaskAllocation.setReceiverName(receiverName);
			int insertCount = otherTaskAllocationMapper.insert(otherTaskAllocation);
			if(insertCount == 0)
			{
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
			} 
			
			//当前的时间
			Date time = ZhppDateUtil.strToTimestamp(ZhppDateUtil.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss");
			//当前的时间
			
			ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
			zxCreditQuery.initUpdateData(userId, logName);
			zxCreditQuery.setId(dataId);
			zxCreditQuery.setOperatorId(receiverId);
			zxCreditQuery.setOperatorName(receiverName);
			zxCreditQuery.setAcceptDate(time);
			int updateCount = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
			if(updateCount == 0)
			{
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
			} 
			else if(updateCount > 1)
			{
				throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
			}
	    }
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  getBaseSalersman</p>  
	*  <p>Description:  </p>  
	*  @param sqlXmls
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getBaseSalersman(java.lang.String)  
	*  @version  V1.0
	*/
	@Override
	public List<BaseSalersman> getBaseSalersman(String sqlXmls) {
		
		return YwShenQingZxDao.getBaseSalersman(sqlXmls);
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  getDanBaoRenList</p>  
	*  <p>Description:  </p>  
	*  @param QueryFkExt
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getDanBaoRenList(com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt)  
	*  @version  V1.0
	*/
	@Override
	public List<QueryFkVo> getDanBaoRenList(QueryFkExt QueryFkExt) {
		
		return YwShenQingZxDao.getDanBaoRenList(QueryFkExt);
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  countDanBaoRenByExt</p>  
	*  <p>Description:  </p>  
	*  @param QueryFkExt
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#countDanBaoRenByExt(com.zjdiepu.www.model.zpp.ywsl.ext.QueryFkExt)  
	*  @version  V1.0
	*/
	@Override
	public int countDanBaoRenByExt(QueryFkExt QueryFkExt) {
		
		return YwShenQingZxDao.countDanBaoRenByExt(QueryFkExt);
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  getZxDataResultList</p>  
	*  <p>Description:  </p>  
	*  @param zxDataResult
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#getZxDataResultList(com.zjdiepu.www.model.zpp.pub.ext.ZxDataResult)  
	*  @version  V1.0
	*/
	@Override
	public List<ZxDataResult> getZxDataResultList(ZxDataResult zxDataResult) {
		
		return YwShenQingZxDao.getZxDataResultList(zxDataResult);
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  countZxDataResult</p>  
	*  <p>Description:  </p>  
	*  @param zxDataResult
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShenQingZxService#countZxDataResult(com.zjdiepu.www.model.zpp.pub.ext.ZxDataResult)  
	*  @version  V1.0
	*/
	@Override
	public int countZxDataResult(ZxDataResult zxDataResult) {
		
		return YwShenQingZxDao.countZxDataResult(zxDataResult);
	}
	
	/**
	 * 检查是否正在申请中
	 * @param querycredExt
	 */
	private void checkApplyingZx(QuerycredExt querycredExt, boolean auto) {
		if(null == querycredExt) {
			return;
		}
		//@add 2018-03-15添加征信中检查，接口申请征信中，不能继续申请=============开始==============
		QuerycreditapplyExt zjr = querycredExt.getKehuExt();
		String zjrNo = Optional.ofNullable(zjr).map(item -> item.getCustomer_no()).orElse(null);
		boolean applyingZx = false;
		if(StringUtils.isNotBlank(zjrNo)) {
			if(auto) {
				applyingZx = zxCreditQueryService.checkAutoApplyingZx(zjrNo);
			} else {
				applyingZx = zxCreditQueryService.checkApplyingZx(zjrNo);
			}
		}
		if(applyingZx) {
			ExceptionHelper.thow(ResultFlagType.APPLYING_ZX.getCode().toString(), String.format(ResultFlagType.APPLYING_ZX.getValue(), zjr.getCustomer_name(), zjrNo));
		}
		
		QuerycreditapplyExt po = querycredExt.getPoExt();
		String poNo = Optional.ofNullable(po).map(item -> item.getCustomer_no()).orElse(null);
		if(StringUtils.isNotBlank(poNo)) {
			if(auto) {
				applyingZx = zxCreditQueryService.checkAutoApplyingZx(poNo);
			} else {
				applyingZx = zxCreditQueryService.checkApplyingZx(poNo);
			}
		}
		if(applyingZx) {
			ExceptionHelper.thow(ResultFlagType.APPLYING_ZX.getCode().toString(), String.format(ResultFlagType.APPLYING_ZX.getValue(), po.getCustomer_name(), poNo));
		}
		
		QuerycreditapplyExt db1 = querycredExt.getDb1Ext();
		String db1No = Optional.ofNullable(db1).map(item -> item.getCustomer_no()).orElse(null);
		if(StringUtils.isNotBlank(db1No)) {
			if(auto) {
				applyingZx = zxCreditQueryService.checkAutoApplyingZx(db1No);
			} else {
				applyingZx = zxCreditQueryService.checkApplyingZx(db1No);
			}
		}
		if(applyingZx) {
			ExceptionHelper.thow(ResultFlagType.APPLYING_ZX.getCode().toString(), String.format(ResultFlagType.APPLYING_ZX.getValue(), db1.getCustomer_name(), db1No));
		}
		QuerycreditapplyExt db2 = querycredExt.getDb2Ext();
		String db2No = Optional.ofNullable(db2).map(item -> item.getCustomer_no()).orElse(null);
		if(StringUtils.isNotBlank(db2No)) {
			if(auto) {
				applyingZx = zxCreditQueryService.checkAutoApplyingZx(db2No);
			} else {
				applyingZx = zxCreditQueryService.checkApplyingZx(db2No);
			}
		}
		if(applyingZx) {
			ExceptionHelper.thow(ResultFlagType.APPLYING_ZX.getCode().toString(), String.format(ResultFlagType.APPLYING_ZX.getValue(), db2.getCustomer_name(), db2No));
		}
		QuerycreditapplyExt db3 = querycredExt.getDb3Ext();
		String db3No = Optional.ofNullable(db3).map(item -> item.getCustomer_no()).orElse(null);
		if(StringUtils.isNotBlank(db3No)) {
			if(auto) {
				applyingZx = zxCreditQueryService.checkAutoApplyingZx(db3No);
			} else {
				applyingZx = zxCreditQueryService.checkApplyingZx(db3No);
			}
		}
		if(applyingZx) {
			ExceptionHelper.thow(ResultFlagType.APPLYING_ZX.getCode().toString(), String.format(ResultFlagType.APPLYING_ZX.getValue(), db3.getCustomer_name(), db3No));
		}
		QuerycreditapplyExt db4 = querycredExt.getDb4Ext();
		String db4No = Optional.ofNullable(db4).map(item -> item.getCustomer_no()).orElse(null);
		if(StringUtils.isNotBlank(db4No)) {
			if(auto) {
				applyingZx = zxCreditQueryService.checkAutoApplyingZx(db4No);
			} else {
				applyingZx = zxCreditQueryService.checkApplyingZx(db4No);
			}
		}
		if(applyingZx) {
			ExceptionHelper.thow(ResultFlagType.APPLYING_ZX.getCode().toString(), String.format(ResultFlagType.APPLYING_ZX.getValue(), db4.getCustomer_name(), db4No));
		}
		//@add 2018-03-15添加征信中检查，接口申请征信中，不能继续申请=============结束==============
	}
	
	@Override
	public void diepuAutoZxApply(AbstractSysUser currentUser,QuerycredExt querycredExt) throws Exception {
		
		checkApplyingZx(querycredExt, true);
		String zxQueryCreditApplySubId = null;
		String queryCreditApplyId = null;
		
		List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = new ArrayList<ZxQueryCreditApplySub>();
		//必须有条数据信息(主借人)
		//获取征信客户的信息数据
		QuerycreditapplyExt zjr = querycredExt.getKehuExt();
		if(null != zjr && StringUtils.isNotBlank(zjr.getCustomer_name()))
		{
			//添加主借人
			zjr.setTypeData(TypeData.HZICBC.getCode());
			ZxQueryCreditApplySub zxQueryCreditApplySub = saveZhuJieRen(zjr, currentUser);
			zxQueryCreditApplySubId = "主借人";
			queryCreditApplyId = zjr.getId();
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
		}
		
		//配偶执行添加
		QuerycreditapplyExt po = querycredExt.getPoExt();
		if(null != po && StringUtils.isNotBlank(po.getCustomer_name()))
		{
			//添加配偶信息
			po.setTypeData(TypeData.HZICBC.getCode());
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(po,zxQueryCreditApplySubId,currentUser);
			queryCreditApplyId = po.getId();
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
		}
		
		//担保人1执行添加
		QuerycreditapplyExt db1 = querycredExt.getDb1Ext();
		if(null != db1 && StringUtils.isNotBlank(db1.getCustomer_name()))
		{
			//添加担保人
			db1.setTypeData(TypeData.HZICBC.getCode());
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(db1,zxQueryCreditApplySubId,currentUser);
			queryCreditApplyId = db1.getId();
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
		}
		
		//担保人2执行添加
		QuerycreditapplyExt db2 = querycredExt.getDb2Ext();
		if(null != db2 && StringUtils.isNotBlank(db2.getCustomer_name()))
		{
			//添加担保人
			db2.setTypeData(TypeData.HZICBC.getCode());
			ZxQueryCreditApplySub zxQueryCreditApplySub =  diepuPeiDanBaoRen(db2,zxQueryCreditApplySubId,currentUser);
			queryCreditApplyId = db2.getId();
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
		}
		
		//担保人3执行添加
		QuerycreditapplyExt db3 = querycredExt.getDb3Ext();
		if(null != db3 && StringUtils.isNotBlank(db3.getCustomer_name()))
		{
			//添加担保人
			db3.setTypeData(TypeData.HZICBC.getCode());
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(db3,zxQueryCreditApplySubId,currentUser);
			queryCreditApplyId = db3.getId();
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
		}
		
		//担保人4执行添加
		QuerycreditapplyExt db4 = querycredExt.getDb4Ext();
		if(null != db4 && StringUtils.isNotBlank(db4.getCustomer_name()))
		{
			//添加担保人
			db4.setTypeData(TypeData.HZICBC.getCode());
			ZxQueryCreditApplySub zxQueryCreditApplySub = diepuPeiDanBaoRen(db4,zxQueryCreditApplySubId,currentUser);
			queryCreditApplyId = db4.getId();
			zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
		}
		
		//验证身份证号码是否重复
		serviceHelper.checkIdNoDuplicate(queryCreditApplyId);
		
		//检查主借人担保人配偶是否在30天之内
		diepuTransferApplyQuery(currentUser, queryCreditApplyId, zxQueryCreditApplySubs, true, true);
	}
	
	/**
	 * 内勤或者业务员提交查征信后，主程序同时将相应信息发送到该接口。
	 * 入参：征信申请主表对象、征信申请子表对象（可能有多个）、征信查询结果对象（工行版）（可能有多个）
	 * 出参：处理结果（成功：0  ； 异常  01xxxx）
	 * 1、将征信主表对象和子表对象写入 transfer_zx_query_credit_apply 和 transfer_zx_query_credit_apply_sub （type_data =3）
	 * 2、将征信查询结果对象（工行版）写入征信查询结果对象（工行版）（type_data =3；transfer_handle_status = 10）
	 * 3、写一个时间为5分钟（可配）之后的下载附件定时任务；  张郑健
	 * 4、写一个时间为10分钟（可配）之后的向工行申请查征信定时任务  张郑健
	 * @param diepuZxCopyApplyRequest
	 * @param partner
	 * @return
	 * @throws BasePartnerException
	 */
	private void diepuZxCopyApplyApi(AbstractSysUser currentUser,String queryCreditApplyId,String bankOrderNo) throws Exception
	{
		if(null == currentUser)
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		
		String userId = currentUser.getId();
		String loginName = currentUser.getName();
		if(StringUtils.isBlank(userId) || StringUtils.isBlank(loginName))
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		
		DiepuZxCopyApplyRequest diepuZxCopyApplyRequest = new DiepuZxCopyApplyRequest();
		diepuZxCopyApplyRequest.userId = userId;
		diepuZxCopyApplyRequest.loginName = loginName;
		
		ZxQueryCreditApply zxQueryCreditApply = zxQueryCreditApplyMapper.selectByPrimaryKey(queryCreditApplyId);
		if(null == zxQueryCreditApply)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplyMapper selectByPrimaryKey is null");
		}
		
		BeanUtils.copyProperties(zxQueryCreditApply, diepuZxCopyApplyRequest.transferZxQueryCreditApply);
		diepuZxCopyApplyRequest.transferZxQueryCreditApply.setBankOrderNo(bankOrderNo);
		
		ZxQueryCreditApplySubExt zxQueryCreditApplySubExt = new ZxQueryCreditApplySubExt();
		zxQueryCreditApplySubExt.withOutPage();
		zxQueryCreditApplySubExt.setQueryCreditApplyId(queryCreditApplyId);
		List<ZxQueryCreditApplySub> queryCreditApplySubList = zxQueryCreditApplySubMapper.selectByExt(zxQueryCreditApplySubExt);
		if(null == queryCreditApplySubList || queryCreditApplySubList.size() == 0)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplySubMapper.selectByExt is null");
		}
		
		//提交过的就不要在提交了  30天之外依然可以提交
		List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = new ArrayList<ZxQueryCreditApplySub>();
		for(int i=0;i<queryCreditApplySubList.size();i++)
		{
			ZxQueryCreditApplySub sub = queryCreditApplySubList.get(i);
			String cusNo = sub.getCusNo();
			
			String sqlXmls1 = "select t.id,t.ccol2,t.ccol3 from zx_query_credit_apply_sub t where t.cus_no = '"+cusNo+"' and t.dp_status = 1 and t.type_data = 3  and t.ccol2 is not null and t.ccol2 <> '' order by t.created desc limit 1";
			Map<String, String> maps = publicDao.selectMapsSql(sqlXmls1);
			if(null != maps && !maps.isEmpty())
			{
				if(StringUtils.isNotBlank(maps.get("ccol2")) && StringUtils.isNotBlank(maps.get("ccol3")))
				{
					int ccol2 = Integer.valueOf(maps.get("ccol3"));
					Integer stamp = (ZhppDateUtil.dateConvertStamp() - ccol2) / 86400;
					
					if(stamp > 30)
					{
						zxQueryCreditApplySubs.add(sub);
					}
				}
			}
			
			if(null == maps || maps.isEmpty())
			{
				zxQueryCreditApplySubs.add(sub);
			}
		}
		
		//如果没有不发申请
		if(null == zxQueryCreditApplySubs || zxQueryCreditApplySubs.size() < 1)
		{
			return;
		}
		
		BaseSalersman baseSalersman = baseSalersmanMapper.selectByPrimaryKey(zxQueryCreditApply.getSalersmanIdThen());
		if(null == baseSalersman)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"baseSalersmanMapper selectByPrimaryKey is null");
		}
		
		BaseBusiUnit baseBusiUnit = new BaseBusiUnit();
		baseBusiUnit.setDpStatus(1);
		baseBusiUnit.setOrgCode(baseSalersman.getUnitCode());
		baseBusiUnit = baseBusiUnitMapper.selectRefined(baseBusiUnit);
		if(null == baseBusiUnit)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"baseBusiUnitMapper selectRefined is null");
		}
		
		//获取地区编码
		String areaCode = null;
		String cityId = baseBusiUnit.getCityId();
		if(StringUtils.isNotBlank(cityId) && cityId.length() >= 4) {
			areaCode = cityId.substring(0,4);
		}
		if(StringUtils.isBlank(areaCode)) {
			String provinceId = baseBusiUnit.getProvinceId();
			if(StringUtils.isNotBlank(provinceId) && provinceId.length() >= 4) {
				areaCode = provinceId.substring(0,4);
			}
		}
		
		//插入银行订单号

		
		//插入银行订单号 @update 2018-02-28 添加防重复逻辑
		YwOrdernoBank ywOrdernoBankParam = new YwOrdernoBank();
		ywOrdernoBankParam.setQueryCreditApplyId(queryCreditApplyId);
		ywOrdernoBankParam.setDpStatus(DpStatus.NORMAL.getCode());
		YwOrdernoBank dbYwOrdernoBank = ywOrdernoBankMapper.selectRefined(ywOrdernoBankParam);
		boolean insert = false;
		if(null == dbYwOrdernoBank) {
			insert = true;
			dbYwOrdernoBank = new YwOrdernoBank();
			dbYwOrdernoBank.initInsertData(currentUser.getId(), currentUser.getName());
		} else {
			dbYwOrdernoBank.initUpdateData(currentUser.getId(), currentUser.getName());
		}
		
		dbYwOrdernoBank.setTypeData(3);
		dbYwOrdernoBank.setQueryCreditApplyId(queryCreditApplyId);
		dbYwOrdernoBank.setBankType("HZICBC");
		dbYwOrdernoBank.setOrdeRno(bankOrderNo);
		dbYwOrdernoBank.setAreaId(areaCode);
		if(insert) { //只新增，不修改
			ywOrdernoBankMapper.insert(dbYwOrdernoBank);
		}
		
		BeanUtils.copyProperties(dbYwOrdernoBank, diepuZxCopyApplyRequest.transYwOrdernoBank);
		diepuZxCopyApplyRequest.transYwOrdernoBank.setOrdeRno(bankOrderNo);
		
		for(int i=0;i<zxQueryCreditApplySubs.size();i++)
		{
			ZxQueryCreditApplySub queryCreditApplySub = zxQueryCreditApplySubs.get(i);
			if(null == queryCreditApplySub)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"queryCreditApplySub is null");
			} 
			diepuZxCopyApplyRequest.transferZxQueryCreditApplySub = diepuZxCopyApplyRequest.newTransferZxQueryCreditApplySub();
			BeanUtils.copyProperties(queryCreditApplySub, diepuZxCopyApplyRequest.transferZxQueryCreditApplySub);
			diepuZxCopyApplyRequest.transferZxQueryCreditApplySub.setBankOrderNo(bankOrderNo);
			diepuZxCopyApplyRequest.transferZxQueryCreditApplySubs.add(diepuZxCopyApplyRequest.transferZxQueryCreditApplySub);
			
			//将征信查询结果对象（工行版）写入征信查询结果对象（工行版）（type_data =3；transfer_handle_status = 10）
			ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
			zxCreditQuery.setQueryCreditApplySubId(queryCreditApplySub.getId());
			zxCreditQuery.setDpStatus(1);
			zxCreditQuery = zxCreditQueryMapper.selectRefined(zxCreditQuery);
			if(null == zxCreditQuery)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxCreditQueryMapper selectRefined is null");
			}
			
			diepuZxCopyApplyRequest.transCreditQueryHzicbc = diepuZxCopyApplyRequest.newTransCreditQueryHzicbc();
			BeanUtils.copyProperties(zxCreditQuery, diepuZxCopyApplyRequest.transCreditQueryHzicbc);
			diepuZxCopyApplyRequest.transCreditQueryHzicbc.setBankOrderNo(bankOrderNo);
			diepuZxCopyApplyRequest.transCreditQueryHzicbc.setTransferHandleStatus(10);
			diepuZxCopyApplyRequest.transCreditQueryHzicbcs.add(diepuZxCopyApplyRequest.transCreditQueryHzicbc);
		}
		
		
//		for(int i=0;i<queryCreditApplySubList.size();i++)
//		{
//			ZxQueryCreditApplySub sub = queryCreditApplySubList.get(i);
//			ThreadFactory.THREAD_SERVICE.submit(
//		    	new Thread(){
//		            public void run(){
////		             @update 2018-02-05 @sub_dataid = '" + sub.getId()  添加子id
//	            	  String sqlXmls = "delete from other_attachments where dataid = '"+queryCreditApplyId+"' and attachment_type = 'word' and dp_status = 1 and sub_dataid = '" + sub.getId() + "'";
//	            	  publicDao.deleteWhereSqlXmls(sqlXmls);
//	                  //触发生成word的任务
//	      			  diepuZxdownloadWord(queryCreditApplyId,sub.getCreditPeopleType(),sub.getId(),currentUser);
//		         }
//		    });
//		}
		
		BooleanResponse booleanResponse =  ownDiepuService.diepuZxCopyApply(diepuZxCopyApplyRequest, Partners.HZ_ICBC);
		if(!booleanResponse.getResult())
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"BooleanResponse result false {ownDiepuService.diepuZxQuerySuccessBusiIdUp(diepuZxQuerySuccessBusiIdUpRequest, Partners.HZ_ICBC)}");
		}
		
	}
	
	@Override
	public void diepuCreatedWord(AbstractSysUser currentUser,
			DiepuCreditApplyModifyExt diepuCreditApplyModifyExt) {
		String applyId = diepuCreditApplyModifyExt.getQueryCreditApplyId();
		String subId = diepuCreditApplyModifyExt.getSubId();
		if(StringUtils.isNoneBlank(applyId, subId)) {
			ZxQueryCreditApplySub zxQueryCreditApplySub = zxQueryCreditApplySubService.selectById(applyId);
			if(null != zxQueryCreditApplySub && StringUtils.isNotBlank(zxQueryCreditApplySub.getCreditPeopleType())) {
				diepuRemoveOldZxWord(applyId, subId);
				diepuZxdownloadWord(applyId, zxQueryCreditApplySub.getCreditPeopleType(), subId, currentUser);
			}
		}
	}
	
	@Override
	public void diepuCreatedWord(AbstractSysUser currentUser,
			ZxRestRequest zxRestRequest) {
		List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = zxRestRequest.getZxQueryCreditApplySubs();
		String applyId = null;
		String applySubId = null;
		String role = null;
		for(ZxQueryCreditApplySub zxQueryCreditApplySub : zxQueryCreditApplySubs) {
			applyId = zxQueryCreditApplySub.getQueryCreditApplyId();
			applySubId = zxQueryCreditApplySub.getId();
			role = zxQueryCreditApplySub.getCreditPeopleType();
			if(StringUtils.isNoneBlank(applyId, applySubId, role)) {
				diepuRemoveOldZxWord(applyId, applySubId);
				diepuZxdownloadWord(applyId, role, applySubId,currentUser);
			}
		}
		
		
	}
	
	@Override
	public void diepuCreatedWord(AbstractSysUser currentUser,
			QuerycredExt querycredExt) {
			//开始生成征信文档
		    String applyId = null;
		    QuerycreditapplyExt kehuExt = querycredExt.getKehuExt();
		    QuerycreditapplyExt poExt = querycredExt.getPoExt();
		    QuerycreditapplyExt db1Ext = querycredExt.getDb1Ext();
		    QuerycreditapplyExt db2Ext = querycredExt.getDb2Ext();
		    QuerycreditapplyExt db3Ext = querycredExt.getDb3Ext();
		    QuerycreditapplyExt db4Ext = querycredExt.getDb4Ext();
			
			if(null != kehuExt && StringUtils.isNotBlank(kehuExt.getCustomer_name())) {
				if(StringUtils.isBlank(applyId)) {
					applyId = kehuExt.getId();
				}
				//触发生成主借人word的任务
				diepuRemoveOldZxWord(applyId, kehuExt.getSubId());
				diepuZxdownloadWord(applyId,"03",kehuExt.getSubId(),currentUser);
			}
			if(null != poExt && StringUtils.isNotBlank(poExt.getCustomer_name())) {
				if(StringUtils.isBlank(applyId)) {
					applyId = poExt.getId();
				}
				//触发生成配偶word的任务
				diepuRemoveOldZxWord(applyId, poExt.getPoDbId());
				diepuZxdownloadWord(applyId,"01",poExt.getPoDbId(),currentUser);
			}
			if(null != db1Ext && StringUtils.isNotBlank(db1Ext.getCustomer_name())) {
				if(StringUtils.isBlank(applyId)) {
					applyId = db1Ext.getId();
				}
				 //触发生成担保人word的任务
				diepuRemoveOldZxWord(applyId, db1Ext.getPoDbId());
				diepuZxdownloadWord(applyId,"02",db1Ext.getPoDbId(),currentUser);
			}
			if(null != db2Ext && StringUtils.isNotBlank(db2Ext.getCustomer_name())) {
				if(StringUtils.isBlank(applyId)) {
					applyId = db2Ext.getId();
				}
				 //触发生成担保人word的任务
				diepuRemoveOldZxWord(applyId, db2Ext.getPoDbId());
				diepuZxdownloadWord(applyId,"02",db2Ext.getPoDbId(),currentUser);
			}
			if(null != db3Ext && StringUtils.isNotBlank(db3Ext.getCustomer_name())) {
				if(StringUtils.isBlank(applyId)) {
					applyId = db3Ext.getId();
				}
				 //触发生成担保人word的任务
				diepuRemoveOldZxWord(applyId, db3Ext.getPoDbId());
				diepuZxdownloadWord(applyId,"02",db3Ext.getPoDbId(),currentUser);
			}
			if(null != db4Ext && StringUtils.isNotBlank(db4Ext.getCustomer_name())) {
				if(StringUtils.isBlank(applyId)) {
					applyId = db4Ext.getId();
				}
				 //触发生成担保人word的任务
				diepuRemoveOldZxWord(applyId, db4Ext.getPoDbId());
				diepuZxdownloadWord(applyId,"02",db4Ext.getPoDbId(),currentUser);
			}
			
			//修改的逻辑
			String zx_query_credit_apply_id = querycredExt.getZx_query_credit_apply_id();
			String zx_query_credit_apply_sub_id = querycredExt.getZx_query_credit_apply_sub_id();
			if(StringUtils.isNoneBlank(zx_query_credit_apply_id, zx_query_credit_apply_sub_id)) {
				ZxQueryCreditApplySub zxQueryCreditApplySub = zxQueryCreditApplySubService.selectById(zx_query_credit_apply_sub_id);
				if(null != zxQueryCreditApplySub && StringUtils.isNotBlank(zxQueryCreditApplySub.getCreditPeopleType())) {
					diepuRemoveOldZxWord(zx_query_credit_apply_id, zx_query_credit_apply_sub_id);
					diepuZxdownloadWord(zx_query_credit_apply_id, zxQueryCreditApplySub.getCreditPeopleType(), zx_query_credit_apply_sub_id, currentUser);
				}
			}
	}
	
	private void diepuRemoveOldZxWord(String applyId, String applySubId) {
		if(StringUtils.isNoneBlank(applyId, applySubId)) {
//			@删除改成逻辑删除
			String sqlXmls = "update other_attachments set dp_status = 3 where dataid = '"+applyId+"' and attachment_type = 'word' and dp_status = 1 and sub_dataid='" + applySubId + "'";
			publicDao.deleteWhereSqlXmls(sqlXmls);
		}
	}
	
	//提交后，触发生成word的任务
	public void diepuZxdownloadWord(String queryCreditApplyId,String creditPeopleType,String zxsubId,AbstractSysUser currentUser)
	{
		if(StringUtils.isBlank(creditPeopleType))
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"creditPeopleType is null");
		}
		
		if(creditPeopleType.equals("03"))
		{
			otherAttachmentsService.saveWordToQiniu(queryCreditApplyId,zxsubId,AttachmentSort.SHEN_FEN_ZHENG_MING, currentUser);
		}
		else if(creditPeopleType.equals("01"))
		{
			otherAttachmentsService.saveWordToQiniu(queryCreditApplyId,zxsubId,AttachmentSort.PEI_OU_SHEN_FEN_ZHENG_MING, currentUser);
		}
		else if(creditPeopleType.equals("02"))
		{
			otherAttachmentsService.saveWordToQiniu(queryCreditApplyId, zxsubId,AttachmentSort.DAN_BAO_REN_SHEN_FEN_ZHENG_MING_1, currentUser);
		}
	}
	
	/**
	 * 征信查询\申请查征信
	 * l根据身份证号码和姓名从zx_征信查询结果表查询是否有30内已经查过的征信结果。如果有，就自动执行征信反馈保存操作（开卡状态、征信状态、信息备注从历史征信结果获取，操作人ID修改为 32个0，操作人姓名修改为【历史征信结果】）  
	 */
	private void diepuTransferApplyQuery(AbstractSysUser currentUser, String queryCreditApplyId, List<ZxQueryCreditApplySub> zxQueryCreditApplySubs, boolean auto, boolean isApply)throws Exception {
		if(CollectionUtils.isNotEmpty(zxQueryCreditApplySubs)) {
			//update 2018-03-28 申请时如果从已有结果生成订单，该对象不为空
			YwBusiness hisCreateBusines = null;
			for(ZxQueryCreditApplySub zxQueryCreditApplySub : zxQueryCreditApplySubs) {
				String cusNo = zxQueryCreditApplySub.getCusNo();
				String bankCode = zxQueryCreditApplySub.getBankCode();
				if(StringUtils.isNotBlank(cusNo)) {
					ZxCreditQuery zxCreditQuery = null;
					if(auto) {
						zxCreditQuery = zxCreditQueryService.checkAutoApplyedZxWithConfigDates(cusNo, bankCode);
					} else {
						zxCreditQuery = zxCreditQueryService.checkApplyedZxWithConfigDates(cusNo, bankCode);
					}
					if(null != zxCreditQuery) {
						String creditResultMark = zxCreditQuery.getCreditResultMark();
						String reasonBack = creditResultMark;
						DiepuCreditFeedbackExt diepuCreditFeedbackExt = new  DiepuCreditFeedbackExt();
						diepuCreditFeedbackExt.setCustName(zxQueryCreditApplySub.getCusName());
						diepuCreditFeedbackExt.setCusNo(cusNo);
	        			diepuCreditFeedbackExt.setResult(BankCreditResultType.ZHENG_CHANG.getCode());
	        			diepuCreditFeedbackExt.setCreditPeopleType(zxQueryCreditApplySub.getCreditPeopleType());
	        			diepuCreditFeedbackExt.setCreditResult(zxCreditQuery.getCreditResult());
	        			diepuCreditFeedbackExt.setOnceCarStatus(zxCreditQuery.getOnceCarStatus());
	        			diepuCreditFeedbackExt.setCreditResultMark(creditResultMark);
	        			diepuCreditFeedbackExt.setQueryCreditApplyId(zxQueryCreditApplySub.getQueryCreditApplyId());
	        			diepuCreditFeedbackExt.setCreditApplySubId(zxQueryCreditApplySub.getId());
	        			diepuCreditFeedbackExt.setReasonBack(reasonBack);
	        			diepuCreditFeedbackExt.setStartDate(zxCreditQuery.getStartDate());
	        			diepuCreditFeedbackExt.setEndDate(zxCreditQuery.getEndDate());
	        			diepuCreditFeedbackExt.setLoanCrdt(zxCreditQuery.getLoanCrdt());
	        			diepuCreditFeedbackExt.setCardCrdt(zxCreditQuery.getCardCrdt());
	        			Double leftAmount = zxCreditQuery.getLeftAmount();
	        			diepuCreditFeedbackExt.setLeftAmount(null == leftAmount ? null : String.valueOf(leftAmount));
	        			Integer leftNum = zxCreditQuery.getLeftNum();
	        			diepuCreditFeedbackExt.setLeftNum(null == leftNum ? null : String.valueOf(leftNum));
	        			SysUser sysUser = new SysUser();
	    				sysUser.setId("00000000000000000000000000000000");
	    				sysUser.setUname("历史征信结果");
	        			hisCreateBusines = icbcApiService.diepuCreditFeedback(sysUser,diepuCreditFeedbackExt);
					}
				}
			}
			
			String bankOrderNo = "";
			String ccol3 = zxQueryCreditApplySubs.get(0).getCcol3();
			for(int x=0;x<zxQueryCreditApplySubs.size();x++) {
				// @update 如果配偶或注解人已经查询过，直接返回已有的订单号 （担保人不匹配）  2018-03-09 xiongxiaotun 
				ZxQueryCreditApplySub zxQueryCreditApplySub_ = zxQueryCreditApplySubs.get(x);
				if(CreditPeopleType.DAN_BAO_REN.getCode().equals(zxQueryCreditApplySub_.getCreditPeopleType())) {
					continue;
				}
				String sqlXmls = "select t.id,t.query_credit_apply_id from zx_query_credit_apply_sub t where t.cus_no = '"+zxQueryCreditApplySub_.getCusNo()+"' and t.dp_status = 1 and t.type_data = 3 and t.credit_people_type in ('01', '03')";
				List<Map<String, String>> resutMpas = publicDao.queryWhereSql(sqlXmls);
				if(null != resutMpas && resutMpas.size() > 0) {
					for(int i=0;i<resutMpas.size();i++) {
		    			Map<String, String> map = resutMpas.get(i);
		    			ZxQueryCreditApplySub zxQueryCreditApplySub = zxQueryCreditApplySubMapper.selectByPrimaryKey(map.get("id"));
		    			if(null != zxQueryCreditApplySub) {
		    				YwOrdernoBank ywOrdernoBank = new YwOrdernoBank();
		    				ywOrdernoBank.setQueryCreditApplyId(zxQueryCreditApplySub.getQueryCreditApplyId());
		    				ywOrdernoBank.setDpStatus(DpStatus.NORMAL.getCode());
		    				ywOrdernoBank.setTypeData(TypeData.HZICBC.getCode());
		    				ywOrdernoBank = ywOrdernoBankMapper.selectRefined(ywOrdernoBank);
		    				if(null != ywOrdernoBank) {
		    					bankOrderNo = ywOrdernoBank.getOrdeRno();
		    					if(StringUtils.isNotBlank(bankOrderNo)) {
		    						break;
		    					}
		    				}
		    			}
		    		}
				}
			}
			
			if(isApply && StringUtils.isBlank(bankOrderNo)) {
				//银行订单号
				bankOrderNo = "HZICBC_" + ZhppDateUtil.DateToString(new Date(), "yyyyMMdd") + new DecimalFormat("000000").format(serialNumberService.createSerialNumber(CodeType.BANK_ORDER_NO,null, true));
			} else {
				YwOrdernoBank ywOrdernoBankParam = new YwOrdernoBank();
				ywOrdernoBankParam.setQueryCreditApplyId(queryCreditApplyId);
				ywOrdernoBankParam.setDpStatus(DpStatus.NORMAL.getCode());
				ywOrdernoBankParam.setTypeData(TypeData.HZICBC.getCode());
				YwOrdernoBank ywOrdernoBank = ywOrdernoBankMapper.selectRefined(ywOrdernoBankParam);
				if(null == ywOrdernoBank) {
					ExceptionHelper.thow(ResultFlagType.MISSING.getCode().toString(), "银行订单记录丢失");
				}
				bankOrderNo = ywOrdernoBank.getOrdeRno();
			}
			
			if(StringUtils.isBlank(bankOrderNo)) {
				ExceptionHelper.thow(ResultFlagType.MISSING.getCode().toString(), "即将申请，但银行订单号为空，请联系服务人员处理！");
			}
			
			//调用中转服务器接口
			diepuZxCopyApplyApi(currentUser,queryCreditApplyId,bankOrderNo);
			
			if(StringUtils.isBlank(ccol3))
			{
				ZxQueryCreditApply zxQueryCreditApply = zxQueryCreditApplyMapper.selectByPrimaryKey(queryCreditApplyId);
				if(null == zxQueryCreditApply)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplyMapper selectByPrimaryKey is null");
				}
				
				BaseSalersman baseSalersman = baseSalersmanMapper.selectByPrimaryKey(zxQueryCreditApply.getSalersmanIdThen());
				if(null == baseSalersman)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"baseSalersmanMapper selectByPrimaryKey is null");
				}
				
				BaseBusiUnit baseBusiUnit = new BaseBusiUnit();
				baseBusiUnit.setDpStatus(1);
				baseBusiUnit.setOrgCode(baseSalersman.getUnitCode());
				baseBusiUnit = baseBusiUnitMapper.selectRefined(baseBusiUnit);
				if(null == baseBusiUnit)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"baseBusiUnitMapper selectRefined is null");
				}
				
				//获取地区编码
				String areaCode = null;
				String cityId = baseBusiUnit.getCityId();
				if(StringUtils.isNotBlank(cityId) && cityId.length() >= 4) {
					areaCode = cityId.substring(0,4);
				}
				if(StringUtils.isBlank(areaCode)) {
					String provinceId = baseBusiUnit.getProvinceId();
					if(StringUtils.isNotBlank(provinceId) && provinceId.length() >= 4) {
						areaCode = provinceId.substring(0,4);
					}
				}
				
				//插入银行订单号 @update 2018-02-28 添加防重复逻辑
				YwOrdernoBank ywOrdernoBankParam = new YwOrdernoBank();
				ywOrdernoBankParam.setQueryCreditApplyId(queryCreditApplyId);
				ywOrdernoBankParam.setDpStatus(DpStatus.NORMAL.getCode());
				YwOrdernoBank dbYwOrdernoBank = ywOrdernoBankMapper.selectRefined(ywOrdernoBankParam);
				if(null == dbYwOrdernoBank) {
					dbYwOrdernoBank = new YwOrdernoBank();
					dbYwOrdernoBank.initInsertData(currentUser.getId(), currentUser.getName());
					if(null != hisCreateBusines) {
						dbYwOrdernoBank.setBusiId(hisCreateBusines.getId());
					}
					dbYwOrdernoBank.setTypeData(TypeData.HZICBC.getCode());
					dbYwOrdernoBank.setQueryCreditApplyId(queryCreditApplyId);
					dbYwOrdernoBank.setBankType("HZICBC");
					dbYwOrdernoBank.setOrdeRno(bankOrderNo);
					dbYwOrdernoBank.setAreaId(areaCode);
					ywOrdernoBankMapper.insert(dbYwOrdernoBank);
				} else {
					YwOrdernoBank updateYwOrdernoBank = new YwOrdernoBank();
					updateYwOrdernoBank.setId(dbYwOrdernoBank.getId());
					updateYwOrdernoBank.initUpdateData(currentUser.getId(), currentUser.getName());
					if(null != hisCreateBusines) {
						updateYwOrdernoBank.setBusiId(hisCreateBusines.getId());
					}
					ywOrdernoBankMapper.updateByPrimaryKeySelective(updateYwOrdernoBank);
				}
			}
		}
	}
	
	/**
	 * 征信查询\申请查征信
	 * l根据身份证号码和姓名从zx_征信查询结果表查询是否有30内已经查过的征信结果。如果有，就自动执行征信反馈保存操作（开卡状态、征信状态、信息备注从历史征信结果获取，操作人ID修改为 32个0，操作人姓名修改为【历史征信结果】）  
	 */
	private void diepuApplyQuery(AbstractSysUser currentUser,List<ZxQueryCreditApplySub> zxQueryCreditApplySubs,String bankCode)throws Exception {
		for(ZxQueryCreditApplySub zxQueryCreditApplySub : zxQueryCreditApplySubs) {
			String applyId = zxQueryCreditApplySub.getQueryCreditApplyId();
			String applySubId = zxQueryCreditApplySub.getId();
			String cusNo = zxQueryCreditApplySub.getCusNo();
			
			ZxCreditQuery zxCreditQuery = zxCreditQueryService.checkApplyedZxWithConfigDates(cusNo, bankCode);
	    	if(zxCreditQuery != null) {
	    		String queryId = zxCreditQuery.getId();
				QueryFkExt queryFkExt = new QueryFkExt();
				queryFkExt.setReplaceId(applyId);
				queryFkExt.setTid(applySubId);
				queryFkExt.setHid(queryId);
				queryFkExt.setQuery_credit_apply_status(QueryCreditApplyStatus.TI_JIAO.getCode());
				queryFkExt.setCredit_query_status(CreditQueryStatus.YI_CHA_XUN.getCode());
				queryFkExt.setStart_date(zxCreditQuery.getStartDate());
				queryFkExt.setEnd_date(zxCreditQuery.getEndDate());
				queryFkExt.setCredit_result(zxCreditQuery.getCreditResult());
				queryFkExt.setOnce_car_status(zxCreditQuery.getOnceCarStatus());
				queryFkExt.setCredit_result_mark(zxCreditQuery.getCreditResultMark());
				SysUser sysUser = new SysUser();
				sysUser.setId("00000000000000000000000000000000");
				sysUser.setUname("历史征信结果");
				diepuZxUpdateStatusTextService(queryFkExt,sysUser);
	    	}
		}
	}

	@Override
	public void diepuAutoZxUpdate(QuerycredExt zxQuerycredExt,AbstractSysUser currentUser, boolean isApply) throws Exception 
	{
		
		String id = currentUser.getId();
		String name = currentUser.getName();
		
		//人员的类型
		//配偶01   担保人02 主借人	03
		String credit_people_type = zxQuerycredExt.getCredit_people_type();
		
		//征信查询结果表  更新
		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
		zxCreditQuery.initUpdateData(id, name);
		zxCreditQuery.setId(zxQuerycredExt.getZx_credit_query_id());
		zxCreditQuery.setBankCode(zxQuerycredExt.getBank_code());
		zxCreditQuery.setSalersmanIdThen(zxQuerycredExt.getSalersman_id_then());
		zxCreditQuery.setCreditQueryStatus(10);
		int count = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxCreditQueryMapper updateByPrimaryKeySelective error");
		} 
		
		if(credit_people_type.equals("03"))
		{
			//征信查询申请
			ZxQueryCreditApply zxQueryCreditApply = new ZxQueryCreditApply();
			zxQueryCreditApply.setId(zxQuerycredExt.getZx_query_credit_apply_id());
			zxQueryCreditApply.initUpdateData(id, name);
			zxQueryCreditApply.setSalersmanIdThen(zxQuerycredExt.getSalersman_id_then());
			zxQueryCreditApply.setBankCode(zxQuerycredExt.getBank_code());
			zxQueryCreditApply.setCustomerName(zxQuerycredExt.getCustomer_name());
			zxQueryCreditApply.setCustomerNo(zxQuerycredExt.getCustomer_no());
			zxQueryCreditApply.setBankCode(zxQuerycredExt.getBank_code());
			zxQueryCreditApply.setQueryCreditApplyStatus(20);
			count = zxQueryCreditApplyMapper.updateByPrimaryKeySelective(zxQueryCreditApply);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplyMapper updateByPrimaryKeySelective error");
			} 
		}
		
		//征信修改的时候如果之前的身份证号码变了
		ZxQueryCreditApplySub applySub = zxQueryCreditApplySubMapper.selectByPrimaryKey(zxQuerycredExt.getZx_query_credit_apply_sub_id());
		if(null == applySub)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplySubMapper selectByPrimaryKey is null");
		}
		
		if(!applySub.getCusNo().equals(zxQuerycredExt.getCustomer_no()))
		{
			String sqlXmls = "update zx_query_credit_apply_sub t set t.ccol2 = '',t.ccol3 = '' where t.id = '"+applySub.getId()+"' and t.dp_status = 1 and t.type_data = 3";
			count = publicDao.updateWhereSqlXmls(sqlXmls);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"publicDao updateWhereSqlXmls error");
			}
		}
		
		ZxQueryCreditApplySub zxQueryCreditApplySub = new ZxQueryCreditApplySub();
		zxQueryCreditApplySub.setId(applySub.getId());
		zxQueryCreditApplySub.initUpdateData(id, name);
		zxQueryCreditApplySub.setBankCode(zxCreditQuery.getBankCode());
		zxQueryCreditApplySub.setCusName(zxQuerycredExt.getCustomer_name());
		zxQueryCreditApplySub.setCusNo(zxQuerycredExt.getCustomer_no());
		zxQueryCreditApplySub.setTel1(zxQuerycredExt.getTel1());
		count = zxQueryCreditApplySubMapper.updateByPrimaryKeySelective(zxQueryCreditApplySub);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxQueryCreditApplySubMapper updateByPrimaryKeySelective error");
		} 
		
		
		//不修改主借人的
		if(!credit_people_type.equals("03"))
		{
			YwBusiness ywBusiness = new YwBusiness();
			ywBusiness.setQueryCreditApplyId(zxQuerycredExt.getZx_query_credit_apply_id());
			ywBusiness.setDpStatus(1);
			ywBusiness = ywBusinessMapper.selectRefined(ywBusiness);
			if(null != ywBusiness)
			{
				YwBusinessBuyer ywBusinessBuyer = new YwBusinessBuyer();
				ywBusinessBuyer.setBusiId(ywBusiness.getId());
				// 需要确认唯一购车人 @update 2018-03-09 
				ywBusinessBuyer.setIdno(zxQuerycredExt.getCustomer_no());
				ywBusinessBuyer.setCarManType(credit_people_type);
				ywBusinessBuyer.setDpStatus(1);
				ywBusinessBuyer = ywBusinessBuyerMapper.selectRefined(ywBusinessBuyer);
				if(null != ywBusinessBuyer)
				{
					ywBusinessBuyer.setName(zxQueryCreditApplySub.getCusName());
					ywBusinessBuyer.setIdno(zxQueryCreditApplySub.getCusNo());
					ywBusinessBuyer.setIdno2(zxQueryCreditApplySub.getCusNo2());
					ywBusinessBuyer.setTel1(zxQueryCreditApplySub.getTel1());
					
					//获取户籍信息
					Map<String,Object> jsonMaps = phoneNubmerAddrService.getIdCordInfo(zxQueryCreditApplySub.getCusNo());
					if(null != jsonMaps && !jsonMaps.isEmpty())
					{
						JSONObject json = CommonUtil.getJSONObject(jsonMaps.get("result"));	
						int isok = json.getInt("isok");
						if(isok != -1)
						{
							ywBusinessBuyer.setArea(String.valueOf(json.get("area")));
							ywBusinessBuyer.setSex("男".equals(json.getString("sex")) ? "01" : "02");
							ywBusinessBuyer.setFamilyRegister(String.valueOf(json.get("province")));
						}
					}
					
					count = ywBusinessBuyerMapper.updateByPrimaryKeySelective(ywBusinessBuyer);
					if(count < 1)
					{
						throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessBuyerMapper error");
					}
				}
			}
		}
		
		String queryCreditApplyId = zxQuerycredExt.getZx_query_credit_apply_id();
		
		if(null == queryCreditApplyId)
		{
			return;
		}
		
		serviceHelper.checkIdNoDuplicate(queryCreditApplyId);
		
		//征信修改
		List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = new ArrayList<ZxQueryCreditApplySub>();
		ZxQueryCreditApplySub sub = zxQueryCreditApplySubMapper.selectByPrimaryKey(applySub.getId());
		sub.setCcol3("退回修改");
		zxQueryCreditApplySubs.add(sub);
		diepuTransferApplyQuery(currentUser, queryCreditApplyId, zxQueryCreditApplySubs, true, false);
	}
	
	/**
	 * 检查是否正在申请中
	 * @add 2018-03-15添加征信中检查，接口申请征信中，不能继续申请
	 * @param querycredExt
	 */
	@Override
	public void checkApplyingZx(ZxRestRequest zxRestRequest, boolean auto) {
		if(null == zxRestRequest) {
			return;
		}
		List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = zxRestRequest.getZxQueryCreditApplySubs();
		if(CollectionUtils.isNotEmpty(zxQueryCreditApplySubs)) {
			for(ZxQueryCreditApplySub zxQueryCreditApplySub : zxQueryCreditApplySubs) {
				String cusNo = Optional.ofNullable(zxQueryCreditApplySub).map(item -> item.getCusNo()).orElse(null);
				boolean applyingZx = false;
				if(StringUtils.isNotBlank(cusNo)) {
					if(auto) {
						applyingZx = zxCreditQueryService.checkAutoApplyingZx(cusNo);
					} else {
						applyingZx = zxCreditQueryService.checkApplyingZx(cusNo);
					}
				}
				if(applyingZx) {
					ExceptionHelper.thow(ResultFlagType.APPLYING_ZX.getCode().toString(), String.format(ResultFlagType.APPLYING_ZX.getValue(), zxQueryCreditApplySub.getCusName(), cusNo));
				}
			}
		}
	}

	@Override
	public void diepuCreditApply(ZxRestRequest zxRestRequest,SysUser currentUser) throws Exception
	{
		checkApplyingZx(zxRestRequest, false);
		
		ZxQueryCreditApply zxQueryCreditApply = zxRestRequest.getZxQueryCreditApply();
		String applyId = zxQueryCreditApply.getId();
		zxQueryCreditApply.initInsertData(currentUser.getId(), currentUser.getName());
		zxQueryCreditApply.setTypeData(3);
		zxQueryCreditApply.setId(applyId);
		DecimalFormat decimalFormat = new DecimalFormat("00000000");
		Integer queryCreditApplySerialNumber = serialNumberService.createSerialNumber(CodeType.CREDIT_APPLY, null, true);
		Date now = new Date();
		String formatNow = DateUtil.dateToFormat(now, "yyyyMMdd");
		
		String queryCreditApplyCode = "ZXCXSQ" + formatNow + decimalFormat.format(queryCreditApplySerialNumber);
		zxQueryCreditApply.setQueryCreditApplyCode(queryCreditApplyCode);
		zxQueryCreditApply.setQueryCreditApplyStatus(QueryCreditApplyStatus.TI_JIAO.getCode());
		zxQueryCreditApply.setCustomerNo2(StringUtil.subWithNHeadMTail(zxQueryCreditApply.getCustomerNo(), 5, 4, "*"));
		List<ZxCreditQuery> zxCreditQuerys = CollectionInitUtil.emptyList();
    	List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = zxRestRequest.getZxQueryCreditApplySubs();
    	for(ZxQueryCreditApplySub zxQueryCreditApplySub : zxQueryCreditApplySubs) {
    		String applySubId = zxQueryCreditApplySub.getId();
    		zxQueryCreditApplySub.initInsertData(currentUser.getId(), currentUser.getName());
    		zxQueryCreditApplySub.setTypeData(TypeData.HZICBC.getCode());
    		zxQueryCreditApplySub.setId(applySubId);
    		zxQueryCreditApplySub.setQueryCreditApplyId(applyId);
    		zxQueryCreditApplySub.setQueryStatus(CreditQueryStatus.DAI_CHA_XUN.getCode());
    		
    		//征信查询表添加
    		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
    		Integer creditQuerySerialNumber = serialNumberService.createSerialNumber(CodeType.CREDIT_QUERY, null, true);
    		String zxCreditQueryCode = "ZXCX" + formatNow + decimalFormat.format(creditQuerySerialNumber);
    		
    		zxCreditQuery.initInsertData(currentUser.getId(), currentUser.getName());
    		zxCreditQuery.setTypeData(TypeData.HZICBC.getCode());
    		zxCreditQuery.setCreditQueryStatus(CreditQueryStatus.DAI_CHA_XUN.getCode());
    		zxCreditQuery.setCreditQueryCode(zxCreditQueryCode);
    		zxCreditQuery.setQueryCreditApplyId(applyId);
    		zxCreditQuery.setQueryCreditApplySubId(applySubId);
    		zxCreditQuery.setCreditQueryCode(String.valueOf(queryCreditApplyCode));
    		zxCreditQuery.setCreditPeopleType(zxQueryCreditApplySub.getCreditPeopleType());
    		zxCreditQuery.setCustomerId(zxQueryCreditApply.getCustomerId());
    		zxCreditQuery.setBankCode(zxQueryCreditApply.getBankCode());
    		zxCreditQuery.setSalersmanIdThen(zxQueryCreditApply.getSalersmanIdThen());
    		zxCreditQuerys.add(zxCreditQuery);
    	}
    	zxQueryCreditApplyMapper.insert(zxQueryCreditApply);
    	zxQueryCreditApplySubMapper.insertBatch(zxQueryCreditApplySubs);
    	zxCreditQueryMapper.insertBatch(zxCreditQuerys);
    	

//      update2018-02-11 提交到中间服务器
    	diepuTransferApplyQuery(currentUser, applyId, zxQueryCreditApplySubs, false, true);
	}

	@Override
	public void diepuCreditApplyModify(DiepuCreditApplyModifyExt diepuCreditApplyModifyExt,SysUser currentUser) throws Exception  {
		String applyId = diepuCreditApplyModifyExt.getQueryCreditApplyId();
		String subId = diepuCreditApplyModifyExt.getSubId();
		
		ZxQueryCreditApplySub zxQueryCreditApplySub = zxQueryCreditApplySubMapper.selectByPrimaryKey(subId);
		if(null == zxQueryCreditApplySub) {
			logger.error("子申请记录丢失。子申请ID：{}。", subId);
			ExceptionHelper.thow(ResultFlagType.MISSING.getCode().toString(),"子申请记录丢失");
		}
		
		ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
		zxCreditQuery.setQueryCreditApplySubId(subId);
		zxCreditQuery.setDpStatus(DpStatus.NORMAL.getCode());
		zxCreditQuery = zxCreditQueryMapper.selectRefined(zxCreditQuery);
		if(null == zxCreditQuery) {
			logger.error("子征信结果记录丢失。子申请ID：{}。", subId);
			ExceptionHelper.thow(ResultFlagType.MISSING.getCode().toString(),"子征信结果记录丢失");
		}
		String creditPeopleType = zxQueryCreditApplySub.getCreditPeopleType();
		if(CreditPeopleType.ZHU_JIE_REN.getCode().equals(creditPeopleType)) {
			ZxQueryCreditApply zxQueryCreditApply = new ZxQueryCreditApply();
			zxQueryCreditApply.setId(applyId);
			zxQueryCreditApply.initUpdateData(currentUser.getId(), currentUser.getName());
			zxQueryCreditApply.setCustomerName(diepuCreditApplyModifyExt.getCusName());
			zxQueryCreditApply.setCustomerNo(diepuCreditApplyModifyExt.getCusNo());
			int count = zxQueryCreditApplyMapper.updateByPrimaryKeySelective(zxQueryCreditApply);
			if(count < 1) {
				logger.error("申请记录丢失。申请ID：{}。", applyId);
				ExceptionHelper.thow(ResultFlagType.MISSING.getCode().toString(),"申请记录丢失");
			}
		}
		zxQueryCreditApplySub.initUpdateData(currentUser.getId(), currentUser.getName());
		zxQueryCreditApplySub.setCusName(diepuCreditApplyModifyExt.getCusName());
		zxQueryCreditApplySub.setCusNo(diepuCreditApplyModifyExt.getCusNo());
		zxQueryCreditApplySub.setTel1(diepuCreditApplyModifyExt.getTel1());
		zxQueryCreditApplySubMapper.updateByPrimaryKeySelective(zxQueryCreditApplySub);
		
		zxCreditQuery.initUpdateData(currentUser.getId(), currentUser.getName());
		zxCreditQuery.setCusName(diepuCreditApplyModifyExt.getCusName());
		zxCreditQuery.setCusNo(diepuCreditApplyModifyExt.getCusNo());
		zxCreditQuery.setCreditQueryStatus(CreditQueryStatus.DAI_CHA_XUN.getCode());
		zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
		
		List<ZxQueryCreditApplySub> zxQueryCreditApplySubs = new ArrayList<ZxQueryCreditApplySub>();
		zxQueryCreditApplySubs.add(zxQueryCreditApplySub);
		
    	Integer typeData = zxQueryCreditApplySub.getTypeData();
    	if(TypeData.HZICBC.getCode().equals(typeData)) { //接口模式
    		diepuTransferApplyQuery(currentUser, applyId, zxQueryCreditApplySubs, false, false);
    	} else if(TypeData.SYSTEM.getCode().equals(typeData)) { //手工模式
    		diepuApplyQuery(currentUser, zxQueryCreditApplySubs,diepuCreditApplyModifyExt.getBankCode());
    	}
	}
}
